-
Notifications
You must be signed in to change notification settings - Fork 4
/
datasource_passwordprofile.go
125 lines (117 loc) · 3.33 KB
/
datasource_passwordprofile.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
114
115
116
117
118
119
120
121
122
123
124
125
package centrify
import (
"fmt"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
logger "github.com/marcozj/golang-sdk/logging"
vault "github.com/marcozj/golang-sdk/platform"
"github.com/marcozj/golang-sdk/restapi"
)
func dataSourcePasswordProfile() *schema.Resource {
return &schema.Resource{
Read: dataSourcePasswordProfileRead,
Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
Description: "The name of password profile",
},
"profile_type": {
Type: schema.TypeString,
Optional: true,
Description: "The type of password profile",
},
// computed attributes
"description": {
Type: schema.TypeString,
Computed: true,
Description: "Description of password profile",
},
"minimum_password_length": {
Type: schema.TypeInt,
Computed: true,
Description: "Minimum password length",
},
"maximum_password_length": {
Type: schema.TypeInt,
Computed: true,
Description: "Maximum password length",
},
"at_least_one_lowercase": {
Type: schema.TypeBool,
Computed: true,
Description: "At least one lower-case alpha character",
},
"at_least_one_uppercase": {
Type: schema.TypeBool,
Computed: true,
Description: "At least one upper-case alpha character",
},
"at_least_one_digit": {
Type: schema.TypeBool,
Computed: true,
Description: "At least one digit",
},
"no_consecutive_repeated_char": {
Type: schema.TypeBool,
Computed: true,
Description: "No consecutive repeated characters",
},
"at_least_one_special_char": {
Type: schema.TypeBool,
Computed: true,
Description: "At least one special character",
},
"maximum_char_occurrence_count": {
Type: schema.TypeInt,
Computed: true,
Description: "Maximum character occurrence count",
},
"special_charset": {
Type: schema.TypeString,
Computed: true,
Description: "Special Characters",
},
"first_character_type": {
Type: schema.TypeString,
Computed: true,
Description: "A leading alpha or alphanumeric character",
},
"last_character_type": {
Type: schema.TypeString,
Computed: true,
Description: "A trailing alpha or alphanumeric character",
},
"minimum_alphabetic_character_count": {
Type: schema.TypeInt,
Computed: true,
Description: "Min number of alpha characters",
},
"minimum_non_alphabetic_character_count": {
Type: schema.TypeInt,
Computed: true,
Description: "Min number of non-alpha characters",
},
},
}
}
func dataSourcePasswordProfileRead(d *schema.ResourceData, m interface{}) error {
logger.Infof("Finding password profile")
client := m.(*restapi.RestClient)
object := vault.NewPasswordProfile(client)
object.Name = d.Get("name").(string)
object.ProfileType = d.Get("profile_type").(string)
err := object.GetByName()
if err != nil {
return fmt.Errorf("error retrieving password profile with name '%s': %s", object.Name, err)
}
d.SetId(object.ID)
schemamap, err := vault.GenerateSchemaMap(object)
if err != nil {
return err
}
//logger.Debugf("Generated Map: %+v", schemamap)
for k, v := range schemamap {
d.Set(k, v)
}
return nil
}