-
Notifications
You must be signed in to change notification settings - Fork 2
/
resource_feed_qualys_vm.go
98 lines (86 loc) · 2.94 KB
/
resource_feed_qualys_vm.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package chronicle
import (
chronicle "github.com/form3tech-oss/terraform-provider-chronicle/client"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
type ResourceFeedQualysVM struct {
TerraformResource *schema.Resource
}
func NewResourceFeedQualysVM() *ResourceFeedQualysVM {
details := &schema.Resource{
Schema: map[string]*schema.Schema{
"hostname": {
Type: schema.TypeString,
Required: true,
Description: `Qualys VM hostname.`,
},
"authentication": {
Type: schema.TypeList,
Required: true,
MaxItems: 1,
Description: `AWS authentication details.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"user": {
Type: schema.TypeString,
Required: true,
Description: `Username.`,
},
"secret": {
Type: schema.TypeString,
Required: true,
Sensitive: true,
Description: `Password.`,
},
},
},
},
},
}
description := "Creates a feed from API source Type for Qualys VM log type."
qualysVM := &ResourceFeedQualysVM{}
qualysVM.TerraformResource = newFeedResourceSchema(details, qualysVM, description, false)
return qualysVM
}
func (f *ResourceFeedQualysVM) getLogType() string {
return chronicle.QualysVMFeedLogType
}
func (f *ResourceFeedQualysVM) expandConcreteFeedConfiguration(d *schema.ResourceData) chronicle.ConcreteFeedConfiguration {
resourceDetailsInterface := readSliceFromResource(d, "details")
if resourceDetailsInterface == nil {
return nil
}
resourceDetails := resourceDetailsInterface[0].(map[string]interface{})
authenticationDetails := resourceDetails["authentication"].([]interface{})[0].(map[string]interface{})
return &chronicle.QualysVMFeedConfiguration{
Hostname: resourceDetails["hostname"].(string),
Authentication: chronicle.QualysVMFeedAuthentication{
User: authenticationDetails["user"].(string),
Secret: authenticationDetails["secret"].(string),
},
}
}
//nolint:all
func (f *ResourceFeedQualysVM) flattenDetailsFromReadOperation(originalConf chronicle.ConcreteFeedConfiguration, readConf chronicle.ConcreteFeedConfiguration) []map[string]interface{} {
readQualysVMConf := readConf.(*chronicle.QualysVMFeedConfiguration)
// Import Case
if originalConf == nil {
return []map[string]interface{}{{
"hostname": readQualysVMConf.Hostname,
"authentication": []map[string]interface{}{{
"user": readQualysVMConf.Authentication.User,
"secret": readQualysVMConf.Authentication.Secret,
}},
}}
}
originalQualysVM := originalConf.(*chronicle.QualysVMFeedConfiguration)
// Default Case
return []map[string]interface{}{{
"hostname": originalQualysVM.Hostname,
// replace authentication block with original values because they are not returned within a read request
"authentication": []map[string]interface{}{{
"user": originalQualysVM.Authentication.User,
"secret": originalQualysVM.Authentication.Secret,
}},
}}
}