-
Notifications
You must be signed in to change notification settings - Fork 2
/
access_rules.go
85 lines (75 loc) · 2.79 KB
/
access_rules.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
// Copyright 2020 StrongDM Inc
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
package sdm
// Code generated by protogen. DO NOT EDIT.
import (
"encoding/json"
"strings"
)
// An AccessRule grants access to a set of Resources. There are two kinds of
// AccessRules:
//
// - Dynamic: a rule which identifies Resources based on their type or tags
// - Static: a rule which contains an explicit list of Resource IDs
type AccessRule struct {
// IDs is a list of Resource IDs granted by this AccessRule. If this field
// is set, the rule is a static access rule. No other fields can be set on a
// static access rule.
IDs []string `json:"ids,omitempty"`
// Type specifies a Resource type. You can set this field by itself to grant
// access to all Resources of a certain type. You can also use it in
// conjunction with the Tags field to further narrow down the scope of
// Resources granted.
//
// See the following link for a list of possible values for this field:
// https://www.strongdm.com/docs/automation/getting-started/filters#h-potentialresourcetypevalues
Type string `json:"type,omitempty"`
// Tags specifies a list of key/value pairs. You can set this field by
// itself to grant access to all Resources which have all the given tags.
// You can also use it in conjunction with the Type field to further narrow
// down the scope of Resources granted.
Tags Tags `json:"tags,omitempty"`
}
// AccessRules define which Resources can be accessed by members of a Role.
type AccessRules []AccessRule
func convertAccessRulesToPorcelain(rules string) (AccessRules, error) {
if rules == "" {
return nil, nil
}
result := AccessRules{}
decoder := json.NewDecoder(strings.NewReader(rules))
decoder.DisallowUnknownFields()
if err := decoder.Decode(&result); err != nil {
return nil, err
}
return result, nil
}
func convertAccessRulesToPlumbing(rules AccessRules) string {
if rules == nil {
rules = AccessRules{}
}
result, _ := json.Marshal(rules)
return string(result)
}
// ParseAccessRulesJSON parses the given access rules JSON string.
func ParseAccessRulesJSON(data string) (AccessRules, error) {
result := AccessRules{}
decoder := json.NewDecoder(strings.NewReader(data))
decoder.DisallowUnknownFields()
if err := decoder.Decode(&result); err != nil {
return nil, err
}
return result, nil
}