This repository has been archived by the owner on Aug 2, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
finish out the data sources for account, host, ha group, and integrat…
…ion instance; including acceptance tests.
- Loading branch information
1 parent
e13bd9c
commit 18a99b4
Showing
15 changed files
with
381 additions
and
35 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
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,5 +1,33 @@ | ||
sudo /vagrant/local/installer.sh -- -multi-tenant -y -elasticsearch-url=http://elastic.xsoar.local:9200 | ||
sudo /vagrant/local/installer.sh -- -multi-tenant -y -elasticsearch-url=http://elastic.xsoar.local:9200 -tools=false | ||
sudo cp /vagrant/local/license /tmp/demisto.lic | ||
sudo chown demisto:demisto /tmp/demisto.lic | ||
sudo cp /tmp/demisto.lic /var/lib/demisto/ | ||
sudo systemctl restart demisto | ||
|
||
# set cookies | ||
until curl --fail --cookie-jar cookie.txt 'https://main.xsoar.local/health' --insecure | ||
do | ||
sleep 5 | ||
done | ||
|
||
# set admin password | ||
XSRF=$(cat cookie.txt | grep XSRF | cut -f 7) | ||
curl --cookie cookie.txt --cookie-jar cookie.txt 'https://main.xsoar.local/login' \ | ||
-H "X-XSRF-TOKEN: ${XSRF}" \ | ||
-H "Content-Type: application/json" \ | ||
--data-raw '{"user":"admin","password":"admin","newPassword":"Xsoar123","passwordValidator":"Xsoar123","loginFailed":true,"passwordExpired":true,"weakNewPassword":false,"reusedOldPassword":false,"userLockedOut":false,"userDisabled":false,"selfUnlockRemainingMinutes":0,"loading":false,"duoFactor":"","passcode":"","shouldShowRegularLogin":false,"userTimeZone":"America/New_York"}' \ | ||
--insecure | ||
|
||
# create api key | ||
curl -u "admin:Xsoar123" --cookie cookie.txt --cookie-jar cookie.txt 'https://main.xsoar.local/apikeys' \ | ||
-H "X-XSRF-TOKEN: ${XSRF}" \ | ||
-H "Content-Type: application/json" \ | ||
--data-raw '{"name":"tf","apikey":"93C67EB97F30E6464DF1E5737F0470E0"}' \ | ||
--insecure | ||
|
||
# set dark mode | ||
curl --cookie cookie.txt 'https://main.xsoar.local/user/update/preferences' \ | ||
-H 'Authorization: 93C67EB97F30E6464DF1E5737F0470E0' \ | ||
-H "Content-Type: application/json" \ | ||
--data-raw '{"id":"admin","homepage":"","investigationPage":"","disableHyperSearch":false,"editorStyle":"","timeZone":"","hours24":"","dateFormat":"","theme":"dark","helpSnippetDisabled":false,"shortcutsDisabled":false,"notificationsSettings":{"email":{"all":true},"pushNotifications":{"all":true}}}' \ | ||
--insecure |
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
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 |
---|---|---|
@@ -1 +1,73 @@ | ||
package xsoar | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/hashicorp/terraform-plugin-framework/tfsdk" | ||
"github.com/hashicorp/terraform-plugin-go/tfprotov6" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestAccAccountDataSource_basic(t *testing.T) { | ||
rName := acctest.RandStringFromCharSet(5, acctest.CharSetAlpha) | ||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccAccountDataSourcePreCheck(t) }, | ||
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ | ||
"xsoar": func() (tfprotov6.ProviderServer, error) { | ||
return tfsdk.NewProtocol6Server(New()), nil | ||
}, | ||
}, | ||
CheckDestroy: testAccCheckAccountDataSourceDestroy(rName), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccAccountDataSourceBasic(rName), | ||
Check: resource.TestCheckResourceAttrPair("data.xsoar_account."+rName, "id", "xsoar_account."+rName, "id"), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccAccountDataSourcePreCheck(t *testing.T) {} | ||
|
||
func testAccCheckAccountDataSourceDestroy(r string) resource.TestCheckFunc { | ||
return func(state *terraform.State) error { | ||
rs, ok := state.RootModule().Resources["xsoar_account."+r] | ||
if !ok { | ||
return fmt.Errorf("not found: %s in %s", r, state.RootModule().Resources) | ||
} | ||
|
||
if rs.Primary.ID == "" { | ||
return fmt.Errorf("No ID is set") | ||
} | ||
|
||
resp, _, err := openapiClient.DefaultApi.GetAccount(context.Background(), "acc_"+r).Execute() | ||
if err != nil { | ||
return fmt.Errorf("Error getting account: " + err.Error()) | ||
} | ||
if resp != nil { | ||
return fmt.Errorf("account returned when it should be destroyed") | ||
} | ||
return nil | ||
} | ||
} | ||
|
||
func testAccAccountDataSourceBasic(name string) string { | ||
c := ` | ||
resource "xsoar_account" "{name}" { | ||
name = "{name}" | ||
host_group_name = "" | ||
account_roles = ["Administrator"] | ||
propagation_labels = [""] | ||
} | ||
data "xsoar_account" "{name}" { | ||
name = xsoar_account.{name}.name | ||
} | ||
` | ||
c = strings.Replace(c, "{name}", name, -1) | ||
return c | ||
} |
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 +1,69 @@ | ||
package xsoar | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/hashicorp/terraform-plugin-framework/tfsdk" | ||
"github.com/hashicorp/terraform-plugin-go/tfprotov6" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestAccHAGroupDataSource_basic(t *testing.T) { | ||
rName := acctest.RandStringFromCharSet(5, acctest.CharSetAlpha) | ||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { testAccHAGroupDataSourcePreCheck(t) }, | ||
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ | ||
"xsoar": func() (tfprotov6.ProviderServer, error) { | ||
return tfsdk.NewProtocol6Server(New()), nil | ||
}, | ||
}, | ||
CheckDestroy: testAccCheckHAGroupDataSourceDestroy(rName), | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testAccHAGroupDataSourceBasic(rName), | ||
Check: resource.TestCheckResourceAttrPair("data.xsoar_ha_group."+rName, "id", "xsoar_ha_group."+rName, "id"), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testAccHAGroupDataSourcePreCheck(t *testing.T) {} | ||
|
||
func testAccCheckHAGroupDataSourceDestroy(r string) resource.TestCheckFunc { | ||
return func(state *terraform.State) error { | ||
rs, ok := state.RootModule().Resources["xsoar_ha_group."+r] | ||
if !ok { | ||
return fmt.Errorf("not found: %s in %s", r, state.RootModule().Resources) | ||
} | ||
|
||
if rs.Primary.ID == "" { | ||
return fmt.Errorf("no ID is set") | ||
} | ||
|
||
_, _, err := openapiClient.DefaultApi.GetHAGroup(context.Background(), r).Execute() | ||
if err != nil { | ||
return nil | ||
} | ||
return fmt.Errorf("found HA group when none was expected: " + err.Error()) | ||
} | ||
} | ||
|
||
func testAccHAGroupDataSourceBasic(name string) string { | ||
c := ` | ||
resource "xsoar_ha_group" "{name}" { | ||
name = "{name}" | ||
elasticsearch_url = "http://elastic.xsoar.local:9200" | ||
elastic_index_prefix = "{name}_" | ||
} | ||
data "xsoar_ha_group" "{name}" { | ||
name = xsoar_ha_group.{name}.name | ||
} | ||
` | ||
c = strings.Replace(c, "{name}", name, -1) | ||
return c | ||
} |
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
Oops, something went wrong.