Skip to content

Commit dc311ee

Browse files
authored
chore: algorithm fields required (#103)
1 parent 16d97e7 commit dc311ee

File tree

4 files changed

+51
-46
lines changed

4 files changed

+51
-46
lines changed

docs/data-sources/setting.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,15 @@ Optional:
6666
<a id="nestedblock--semantic_types"></a>
6767
### Nested Schema for `semantic_types`
6868

69+
Required:
70+
71+
- `id` (String) The semantic type unique uuid.
72+
- `title` (String) The semantic type title. Required.
73+
6974
Optional:
7075

7176
- `algorithm` (Block List, Max: 1) The semantic type algorithm. Required. (see [below for nested schema](#nestedblock--semantic_types--algorithm))
7277
- `description` (String) The semantic type description. Optional.
73-
- `id` (String) The semantic type unique uuid.
74-
- `title` (String) The semantic type title. Required.
7578

7679
<a id="nestedblock--semantic_types--algorithm"></a>
7780
### Nested Schema for `semantic_types.algorithm`
@@ -86,26 +89,26 @@ Optional:
8689
<a id="nestedblock--semantic_types--algorithm--full_mask"></a>
8790
### Nested Schema for `semantic_types.algorithm.full_mask`
8891

89-
Optional:
92+
Required:
9093

9194
- `substitution` (String) Substitution is the string used to replace the original value, the max length of the string is 16 bytes.
9295

9396

9497
<a id="nestedblock--semantic_types--algorithm--inner_outer_mask"></a>
9598
### Nested Schema for `semantic_types.algorithm.inner_outer_mask`
9699

97-
Optional:
100+
Required:
98101

99-
- `prefix_len` (Number)
100-
- `substitution` (String)
101-
- `suffix_len` (Number)
102-
- `type` (String)
102+
- `prefix_len` (Number) The length of prefix.
103+
- `substitution` (String) Substitution is the string used to replace the inner or outer substring.
104+
- `suffix_len` (Number) The length of suffix.
105+
- `type` (String) INNER or OUTER.
103106

104107

105108
<a id="nestedblock--semantic_types--algorithm--md5_mask"></a>
106109
### Nested Schema for `semantic_types.algorithm.md5_mask`
107110

108-
Optional:
111+
Required:
109112

110113
- `salt` (String) Salt is the salt value to generate a different hash that with the word alone.
111114

@@ -120,7 +123,7 @@ Optional:
120123
<a id="nestedblock--semantic_types--algorithm--range_mask--slices"></a>
121124
### Nested Schema for `semantic_types.algorithm.range_mask.slices`
122125

123-
Optional:
126+
Required:
124127

125128
- `end` (Number) End is the stop index of the original value, should be less than the length of the original value.
126129
- `start` (Number) Start is the start index of the original value, start from 0 and should be less than stop.

docs/resources/setting.md

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -121,12 +121,15 @@ Optional:
121121
<a id="nestedblock--semantic_types"></a>
122122
### Nested Schema for `semantic_types`
123123

124+
Required:
125+
126+
- `id` (String) The semantic type unique uuid.
127+
- `title` (String) The semantic type title. Required.
128+
124129
Optional:
125130

126131
- `algorithm` (Block List, Max: 1) The semantic type algorithm. Required. (see [below for nested schema](#nestedblock--semantic_types--algorithm))
127132
- `description` (String) The semantic type description. Optional.
128-
- `id` (String) The semantic type unique uuid.
129-
- `title` (String) The semantic type title. Required.
130133

131134
<a id="nestedblock--semantic_types--algorithm"></a>
132135
### Nested Schema for `semantic_types.algorithm`
@@ -141,26 +144,26 @@ Optional:
141144
<a id="nestedblock--semantic_types--algorithm--full_mask"></a>
142145
### Nested Schema for `semantic_types.algorithm.full_mask`
143146

144-
Optional:
147+
Required:
145148

146149
- `substitution` (String) Substitution is the string used to replace the original value, the max length of the string is 16 bytes.
147150

148151

149152
<a id="nestedblock--semantic_types--algorithm--inner_outer_mask"></a>
150153
### Nested Schema for `semantic_types.algorithm.inner_outer_mask`
151154

152-
Optional:
155+
Required:
153156

154-
- `prefix_len` (Number)
155-
- `substitution` (String)
156-
- `suffix_len` (Number)
157-
- `type` (String)
157+
- `prefix_len` (Number) The length of prefix.
158+
- `substitution` (String) Substitution is the string used to replace the inner or outer substring.
159+
- `suffix_len` (Number) The length of suffix.
160+
- `type` (String) INNER or OUTER.
158161

159162

160163
<a id="nestedblock--semantic_types--algorithm--md5_mask"></a>
161164
### Nested Schema for `semantic_types.algorithm.md5_mask`
162165

163-
Optional:
166+
Required:
164167

165168
- `salt` (String) Salt is the salt value to generate a different hash that with the word alone.
166169

@@ -175,7 +178,7 @@ Optional:
175178
<a id="nestedblock--semantic_types--algorithm--range_mask--slices"></a>
176179
### Nested Schema for `semantic_types.algorithm.range_mask.slices`
177180

178-
Optional:
181+
Required:
179182

180183
- `end` (Number) End is the stop index of the original value, should be less than the length of the original value.
181184
- `start` (Number) Start is the start index of the original value, start from 0 and should be less than stop.

provider/data_source_setting.go

Lines changed: 19 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,12 @@ func getSemanticTypesSetting(computed bool) *schema.Schema {
5050
Schema: map[string]*schema.Schema{
5151
"id": {
5252
Type: schema.TypeString,
53-
Computed: computed,
54-
Optional: true,
53+
Required: true,
5554
Description: "The semantic type unique uuid.",
5655
},
5756
"title": {
5857
Type: schema.TypeString,
59-
Computed: computed,
60-
Optional: true,
58+
Required: true,
6159
Description: "The semantic type title. Required.",
6260
},
6361
"description": {
@@ -85,8 +83,7 @@ func getSemanticTypesSetting(computed bool) *schema.Schema {
8583
Schema: map[string]*schema.Schema{
8684
"substitution": {
8785
Type: schema.TypeString,
88-
Computed: computed,
89-
Optional: true,
86+
Required: true,
9087
Description: "Substitution is the string used to replace the original value, the max length of the string is 16 bytes.",
9188
},
9289
},
@@ -109,20 +106,17 @@ func getSemanticTypesSetting(computed bool) *schema.Schema {
109106
Schema: map[string]*schema.Schema{
110107
"start": {
111108
Type: schema.TypeInt,
112-
Computed: computed,
113-
Optional: true,
109+
Required: true,
114110
Description: "Start is the start index of the original value, start from 0 and should be less than stop.",
115111
},
116112
"end": {
117113
Type: schema.TypeInt,
118-
Computed: computed,
119-
Optional: true,
114+
Required: true,
120115
Description: "End is the stop index of the original value, should be less than the length of the original value.",
121116
},
122117
"substitution": {
123118
Type: schema.TypeString,
124-
Computed: computed,
125-
Optional: true,
119+
Required: true,
126120
Description: "Substitution is the string used to replace the OriginalValue[start:end).",
127121
},
128122
},
@@ -141,8 +135,7 @@ func getSemanticTypesSetting(computed bool) *schema.Schema {
141135
Schema: map[string]*schema.Schema{
142136
"salt": {
143137
Type: schema.TypeString,
144-
Computed: computed,
145-
Optional: true,
138+
Required: true,
146139
Description: "Salt is the salt value to generate a different hash that with the word alone.",
147140
},
148141
},
@@ -157,24 +150,24 @@ func getSemanticTypesSetting(computed bool) *schema.Schema {
157150
Elem: &schema.Resource{
158151
Schema: map[string]*schema.Schema{
159152
"prefix_len": {
160-
Type: schema.TypeInt,
161-
Computed: computed,
162-
Optional: true,
153+
Type: schema.TypeInt,
154+
Required: true,
155+
Description: "The length of prefix.",
163156
},
164157
"suffix_len": {
165-
Type: schema.TypeInt,
166-
Computed: computed,
167-
Optional: true,
158+
Type: schema.TypeInt,
159+
Required: true,
160+
Description: "The length of suffix.",
168161
},
169162
"substitution": {
170-
Type: schema.TypeString,
171-
Computed: computed,
172-
Optional: true,
163+
Type: schema.TypeString,
164+
Required: true,
165+
Description: "Substitution is the string used to replace the inner or outer substring.",
173166
},
174167
"type": {
175-
Type: schema.TypeString,
176-
Computed: computed,
177-
Optional: true,
168+
Type: schema.TypeString,
169+
Required: true,
170+
Description: "INNER or OUTER.",
178171
ValidateFunc: validation.StringInSlice([]string{
179172
v1pb.Algorithm_InnerOuterMask_INNER.String(),
180173
v1pb.Algorithm_InnerOuterMask_OUTER.String(),

provider/resource_setting.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,12 @@ func convertToV1SemanticTypeSetting(d *schema.ResourceData) (*v1pb.SemanticTypeS
387387
}
388388
} else if innerOuterMasks, ok := rawAlgorithm["inner_outer_mask"].([]interface{}); ok && len(innerOuterMasks) == 1 {
389389
innerOuterMask := innerOuterMasks[0].(map[string]interface{})
390+
t := v1pb.Algorithm_InnerOuterMask_MaskType(
391+
v1pb.Algorithm_InnerOuterMask_MaskType_value[innerOuterMask["type"].(string)],
392+
)
393+
if t == v1pb.Algorithm_InnerOuterMask_MASK_TYPE_UNSPECIFIED {
394+
return nil, errors.Errorf("invalid inner_outer_mask type: %s", innerOuterMask["type"].(string))
395+
}
390396
semanticType.Algorithm = &v1pb.Algorithm{
391397
Mask: &v1pb.Algorithm_InnerOuterMask_{
392398
InnerOuterMask: &v1pb.Algorithm_InnerOuterMask{

0 commit comments

Comments
 (0)