generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 41
/
file_store_utils.go
94 lines (82 loc) · 1.89 KB
/
file_store_utils.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
package file_store
import (
"fmt"
"strings"
"github.com/antihax/optional"
"github.com/harness/harness-go-sdk/harness/nextgen"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
const (
orgId = "org_id"
projectId = "project_id"
identifier = "identifier"
fileContentPath = "file_content_path"
name = "name"
parentIdentifier = "parent_identifier"
path = "path"
content = "content"
description = "description"
mimeType = "mime_type"
tags = "tags"
type_ = "type"
fileUsage = "file_usage"
createdBy = "created_by"
lastModifiedBy = "last_modified_by"
lastModifiedAt = "last_modified_at"
draft = "draft"
)
func buildTagsJson(tags *schema.Set) string {
result := "["
tagMap := make(map[string]string)
for i := 0; i < tags.Len(); i++ {
tag := fmt.Sprintf("%v", tags.List()[i])
if strings.Contains(tag, ":") {
splitTag := strings.Split(tag, ":")
key := splitTag[0]
value := splitTag[1]
tagMap[key] = value
} else {
tagMap[tag] = ""
}
}
first := true
for key, value := range tagMap {
if !first {
result += ","
} else {
first = false
}
result += fmt.Sprintf(`{"key":"%s","value":"%s"}`, key, value)
}
result += "]"
return result
}
func FlattenTags(tags []nextgen.NgTag) []string {
var result []string
for _, tag := range tags {
result = append(result, tag.Key+":"+tag.Value)
}
return result
}
func getOptionalString(str interface{}) optional.String {
v, ok := str.(string)
if !ok {
return optional.String{}
}
if len(v) == 0 {
return optional.EmptyString()
}
return optional.NewString(v)
}
func getEmail(user *nextgen.EmbeddedUserDetailsDto) string {
if user != nil {
return user.Email
}
return ""
}
func getName(user *nextgen.EmbeddedUserDetailsDto) string {
if user != nil {
return user.Name
}
return ""
}