Skip to content
This repository was archived by the owner on Jul 2, 2021. It is now read-only.

Commit ab7d803

Browse files
liamgadampointer-form3
authored andcommitted
Add skip TLS verification option (#6)
1 parent 766860e commit ab7d803

File tree

8 files changed

+170
-148
lines changed

8 files changed

+170
-148
lines changed

Gopkg.lock

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ You can specify credentials and your AlienVault fully-qualified domain name in t
2020

2121
```hcl
2222
provider "alienvault" {
23-
fqdn = "mycompany.alienvault.cloud"
24-
username = "user@email.com"
25-
password = "..."
23+
fqdn = "mycompany.alienvault.cloud"
24+
username = "user@email.com"
25+
password = "..."
26+
skip_tls_verify = false
2627
}
2728
```
2829

alienvault/configure.go

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,24 @@
11
package alienvault
22

33
import (
4-
"github.com/form3tech-oss/alienvault"
5-
"github.com/hashicorp/terraform/helper/schema"
4+
"github.com/form3tech-oss/alienvault"
5+
"github.com/hashicorp/terraform/helper/schema"
66
)
77

88
func providerConfigure(d *schema.ResourceData) (interface{}, error) {
99

10-
client := alienvault.New(
11-
d.Get("fqdn").(string),
12-
alienvault.Credentials{
13-
Username: d.Get("username").(string),
14-
Password: d.Get("password").(string),
15-
})
10+
client := alienvault.New(
11+
d.Get("fqdn").(string),
12+
alienvault.Credentials{
13+
Username: d.Get("username").(string),
14+
Password: d.Get("password").(string),
15+
},
16+
d.Get("skip_tls_verify").(bool),
17+
)
1618

17-
if err := client.Authenticate(); err != nil {
18-
return nil, err
19-
}
19+
if err := client.Authenticate(); err != nil {
20+
return nil, err
21+
}
2022

21-
return client, nil
23+
return client, nil
2224
}

alienvault/configure_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,15 @@ func TestProviderConfigure(t *testing.T) {
3131
"password": &schema.Schema{
3232
Type: schema.TypeString,
3333
},
34+
"skip_tls_verify": &schema.Schema{
35+
Type: schema.TypeBool,
36+
},
3437
}
3538
resourceDataMap := map[string]interface{}{
3639
"fqdn": strings.Replace(ts.URL, "https://", "", -1),
3740
"username": "something",
3841
"password": "something",
42+
"skip_tls_verify": "false",
3943
}
4044
resourceLocalData := schema.TestResourceDataRaw(t, resourceSchema, resourceDataMap)
4145

alienvault/provider.go

Lines changed: 44 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,52 @@
11
package alienvault
22

33
import (
4-
"github.com/hashicorp/terraform/helper/schema"
4+
"github.com/hashicorp/terraform/helper/schema"
5+
"os"
56
)
67

78
// Provider makes the AlienVault provider available
89
func Provider() *schema.Provider {
9-
return &schema.Provider{
10-
Schema: map[string]*schema.Schema{
11-
"fqdn": &schema.Schema{
12-
Type: schema.TypeString,
13-
Required: true,
14-
Description: "The fully qualified domain name for your AlienVault instance e.g. example.alienvault.cloud",
15-
DefaultFunc: schema.EnvDefaultFunc("ALIENVAULT_FQDN", nil),
16-
Sensitive: true,
17-
},
18-
"username": &schema.Schema{
19-
Type: schema.TypeString,
20-
Required: true,
21-
Description: "AV username",
22-
DefaultFunc: schema.EnvDefaultFunc("ALIENVAULT_USERNAME", nil),
23-
Sensitive: true,
24-
},
25-
"password": &schema.Schema{
26-
Type: schema.TypeString,
27-
Required: true,
28-
Description: "AV password",
29-
DefaultFunc: schema.EnvDefaultFunc("ALIENVAULT_PASSWORD", nil),
30-
Sensitive: true,
31-
},
32-
},
33-
ResourcesMap: map[string]*schema.Resource{
34-
"alienvault_job_aws_bucket": resourceJobAWSBucket(),
35-
"alienvault_job_aws_cloudwatch": resourceJobAWSCloudWatch(),
36-
"alienvault_sensor": resourceSensor(),
37-
},
38-
ConfigureFunc: providerConfigure,
39-
}
10+
return &schema.Provider{
11+
Schema: map[string]*schema.Schema{
12+
"fqdn": &schema.Schema{
13+
Type: schema.TypeString,
14+
Required: true,
15+
Description: "The fully qualified domain name for your AlienVault instance e.g. example.alienvault.cloud",
16+
DefaultFunc: schema.EnvDefaultFunc("ALIENVAULT_FQDN", nil),
17+
Sensitive: true,
18+
},
19+
"username": &schema.Schema{
20+
Type: schema.TypeString,
21+
Required: true,
22+
Description: "AV username",
23+
DefaultFunc: schema.EnvDefaultFunc("ALIENVAULT_USERNAME", nil),
24+
Sensitive: true,
25+
},
26+
"password": &schema.Schema{
27+
Type: schema.TypeString,
28+
Required: true,
29+
Description: "AV password",
30+
DefaultFunc: schema.EnvDefaultFunc("ALIENVAULT_PASSWORD", nil),
31+
Sensitive: true,
32+
},
33+
"skip_tls_verify": &schema.Schema{
34+
Type: schema.TypeBool,
35+
Optional: true,
36+
Description: "Skip TLS certificate verification",
37+
DefaultFunc: func() (interface{}, error) {
38+
if v := os.Getenv("ALIENVAULT_SKIP_TLS_VERIFY"); v != "" {
39+
return v == "true" || v == "1", nil
40+
}
41+
return false, nil
42+
},
43+
},
44+
},
45+
ResourcesMap: map[string]*schema.Resource{
46+
"alienvault_job_aws_bucket": resourceJobAWSBucket(),
47+
"alienvault_job_aws_cloudwatch": resourceJobAWSCloudWatch(),
48+
"alienvault_sensor": resourceSensor(),
49+
},
50+
ConfigureFunc: providerConfigure,
51+
}
4052
}

alienvault/provider_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func testAccPreCheck(t *testing.T) {
3333
}
3434

3535
func init() {
36+
_ = os.Setenv("ALIENVAULT_SKIP_TLS_VERIFY", "1")
3637
testAccProvider = Provider()
3738
testAccProviders = map[string]terraform.ResourceProvider{
3839
"alienvault": testAccProvider,

vendor/github.com/form3tech-oss/alienvault/.travis.yml

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)