forked from openshift/insights-operator
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[release-4.8] Bug 2021572: Anonymize identity provider attributes in …
…the (openshift#520) (openshift#527) * Anonymize identity provider attributes in the authentication.operator.openshift.io definition * More robust way....
- Loading branch information
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
package utils | ||
|
||
import ( | ||
"fmt" | ||
"strings" | ||
|
||
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured" | ||
) | ||
|
||
func NestedStringWrapper(obj map[string]interface{}, fields ...string) (string, error) { | ||
s, ok, err := unstructured.NestedString(obj, fields...) | ||
if !ok { | ||
return "", fmt.Errorf("can't find %s", formatSlice(fields...)) | ||
} | ||
if err != nil { | ||
return "", err | ||
} | ||
|
||
return s, nil | ||
} | ||
|
||
func NestedSliceWrapper(obj map[string]interface{}, fields ...string) ([]interface{}, error) { | ||
s, ok, err := unstructured.NestedSlice(obj, fields...) | ||
if !ok { | ||
return nil, fmt.Errorf("can't find %s", formatSlice(fields...)) | ||
} | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return s, nil | ||
} | ||
|
||
func NestedInt64Wrapper(obj map[string]interface{}, fields ...string) (int64, error) { | ||
i, ok, err := unstructured.NestedInt64(obj, fields...) | ||
if !ok { | ||
return 0, fmt.Errorf("can't find %s", formatSlice(fields...)) | ||
} | ||
if err != nil { | ||
return 0, err | ||
} | ||
|
||
return i, nil | ||
} | ||
|
||
func formatSlice(s ...string) string { | ||
var str string | ||
for _, f := range s { | ||
str += fmt.Sprintf("%s.", f) | ||
} | ||
str = strings.TrimRight(str, ".") | ||
return str | ||
} |