-
Notifications
You must be signed in to change notification settings - Fork 5
/
resource_feed_okta_system_log.go
113 lines (100 loc) · 3.3 KB
/
resource_feed_okta_system_log.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package chronicle
import (
chronicle "github.com/form3tech-oss/terraform-provider-chronicle/client"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
type ResourceFeedOktaSystemLog struct {
TerraformResource *schema.Resource
}
func NewResourceFeedOktaSystemLog() *ResourceFeedOktaSystemLog {
details := &schema.Resource{
Schema: map[string]*schema.Schema{
"hostname": {
Type: schema.TypeString,
Required: true,
Description: `Okta hostname.`,
},
"authentication": {
Type: schema.TypeList,
Required: true,
MaxItems: 1,
Description: `Okta authentication header details.`,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"key": {
Type: schema.TypeString,
Required: true,
Description: `Okta authorization key.`,
},
"value": {
Type: schema.TypeString,
Required: true,
Sensitive: true,
Description: `Okta API token.`,
},
},
},
},
},
}
description := "Creates a feed from API source Type for Okta System Log log type."
okta := &ResourceFeedOktaSystemLog{}
okta.TerraformResource = newFeedResourceSchema(details, okta, description, false)
return okta
}
func (f *ResourceFeedOktaSystemLog) getLogType() string {
return chronicle.OktaSystemLogFeedLogType
}
func (f *ResourceFeedOktaSystemLog) 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.OktaSystemLogFeedConfiguration{
Hostname: resourceDetails["hostname"].(string),
Authentication: chronicle.OktaSystemLogFeedAuthentication{
HeaderKeyValues: []chronicle.OktaSystemLogAuthenticationHeaderKeyValues{
{
Key: authenticationDetails["key"].(string),
Value: authenticationDetails["value"].(string),
},
},
},
}
}
//nolint:all
func (f *ResourceFeedOktaSystemLog) flattenDetailsFromReadOperation(originalConf chronicle.ConcreteFeedConfiguration, readConf chronicle.ConcreteFeedConfiguration) []map[string]interface{} {
readOktaConf := readConf.(*chronicle.OktaSystemLogFeedConfiguration)
// Import Case
if originalConf == nil {
var key, value string
if readOktaConf.Authentication.HeaderKeyValues == nil {
key = ""
value = ""
} else {
key = readOktaConf.Authentication.HeaderKeyValues[0].Key
value = readOktaConf.Authentication.HeaderKeyValues[0].Value
}
return []map[string]interface{}{{
"hostname": readOktaConf.Hostname,
"authentication": []map[string]interface{}{{
"key": key,
"value": value,
},
}},
}
}
originalOkta := originalConf.(*chronicle.OktaSystemLogFeedConfiguration)
// Default Case
return []map[string]interface{}{{
"hostname": readOktaConf.Hostname,
// replace authentication block with original values because they are not returned within a read request
"authentication": []map[string]interface{}{{
"key": originalOkta.Authentication.HeaderKeyValues[0].Key,
"value": originalOkta.Authentication.HeaderKeyValues[0].Value,
},
}},
}
}