-
Notifications
You must be signed in to change notification settings - Fork 0
/
organizational_branding_localization.go
151 lines (132 loc) · 4.94 KB
/
organizational_branding_localization.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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
package model
import (
_ "embed"
"encoding/base64"
"fmt"
"github.com/Azure/go-autorest/autorest/to"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/microsoftgraph/msgraph-beta-sdk-go/models"
)
type OrganizationalBrandingLocalization struct {
Id types.String `tfsdk:"id"`
BackgroundColor types.String `tfsdk:"background_color"`
BackgroundImage types.String `tfsdk:"background_image"`
BackgroundImageUrl types.String `tfsdk:"background_image_url"`
BannerLogo types.String `tfsdk:"banner_logo"`
BannerLogoUrl types.String `tfsdk:"banner_logo_url"`
SignInPageText types.String `tfsdk:"sign_in_page_text"`
SquareLogoLight types.String `tfsdk:"square_logo_light"`
SquareLogoLightUrl types.String `tfsdk:"square_logo_light_url"`
SquareLogoDark types.String `tfsdk:"square_logo_dark"`
SquareLogoDarkUrl types.String `tfsdk:"square_logo_dark_url"`
UsernameHintText types.String `tfsdk:"username_hint_text"`
bi []byte
bl []byte
sll []byte
sld []byte
}
func (o *OrganizationalBrandingLocalization) Consume(b models.OrganizationalBrandingLocalizationable) diag.Diagnostics {
if to.String(b.GetBackgroundColor()) == "" {
o.BackgroundColor = types.StringNull()
} else {
o.BackgroundColor = types.StringPointerValue(b.GetBackgroundColor())
}
if to.String(b.GetSignInPageText()) == "" {
o.SignInPageText = types.StringNull()
} else {
o.SignInPageText = types.StringPointerValue(b.GetSignInPageText())
}
if to.String(b.GetUsernameHintText()) == "" {
o.UsernameHintText = types.StringNull()
} else {
o.UsernameHintText = types.StringPointerValue(b.GetUsernameHintText())
}
cdn := b.GetCdnList()
if len(cdn) > 0 && b.GetBannerLogoRelativeUrl() != nil {
o.BannerLogoUrl = types.StringValue(fmt.Sprintf("https://%s/%s", b.GetCdnList()[0], to.String(b.GetBannerLogoRelativeUrl())))
} else {
o.BannerLogoUrl = types.StringNull()
}
if len(cdn) > 0 && b.GetBackgroundImageRelativeUrl() != nil {
o.BackgroundImageUrl = types.StringValue(fmt.Sprintf("https://%s/%s", b.GetCdnList()[0], to.String(b.GetBackgroundImageRelativeUrl())))
} else {
o.BackgroundImageUrl = types.StringNull()
}
if len(cdn) > 0 && b.GetSquareLogoRelativeUrl() != nil {
o.SquareLogoLightUrl = types.StringValue(fmt.Sprintf("https://%s/%s", b.GetCdnList()[0], to.String(b.GetSquareLogoRelativeUrl())))
} else {
o.SquareLogoLightUrl = types.StringNull()
}
if len(cdn) > 0 && b.GetSquareLogoDarkRelativeUrl() != nil {
o.SquareLogoDarkUrl = types.StringValue(fmt.Sprintf("https://%s/%s", b.GetCdnList()[0], to.String(b.GetSquareLogoDarkRelativeUrl())))
} else {
o.SquareLogoDarkUrl = types.StringNull()
}
return nil
}
func (o *OrganizationalBrandingLocalization) Populate(b models.OrganizationalBrandingLocalizationable) diag.Diagnostics {
var diags diag.Diagnostics
if to.String(b.GetBackgroundColor()) != o.BackgroundColor.ValueString() {
b.SetBackgroundColor(o.BackgroundColor.ValueStringPointer())
}
if to.String(b.GetSignInPageText()) != o.SignInPageText.ValueString() {
b.SetSignInPageText(o.SignInPageText.ValueStringPointer())
}
if to.String(b.GetUsernameHintText()) != o.UsernameHintText.ValueString() {
b.SetUsernameHintText(o.UsernameHintText.ValueStringPointer())
}
if !o.BannerLogo.IsNull() {
t := make([]byte, base64.StdEncoding.DecodedLen(len(o.BannerLogo.ValueString())))
_, err := base64.StdEncoding.Decode(t, []byte(o.BannerLogo.ValueString()))
if err != nil {
diags.AddError("failed to upload banner logo", err.Error())
}
o.bl = t
} else {
o.bl = nil
}
if !o.BackgroundImage.IsNull() {
t := make([]byte, base64.StdEncoding.DecodedLen(len(o.BackgroundImage.ValueString())))
_, err := base64.StdEncoding.Decode(t, []byte(o.BackgroundImage.ValueString()))
if err != nil {
diags.AddError("failed to upload background image", err.Error())
}
o.bi = t
} else {
o.bi = nil
}
if !o.SquareLogoLight.IsNull() {
t := make([]byte, base64.StdEncoding.DecodedLen(len(o.SquareLogoLight.ValueString())))
_, err := base64.StdEncoding.Decode(t, []byte(o.SquareLogoLight.ValueString()))
if err != nil {
diags.AddError("failed to upload square logo (light)", err.Error())
}
o.sll = t
} else {
o.sll = nil
}
if !o.SquareLogoDark.IsNull() {
t := make([]byte, base64.StdEncoding.DecodedLen(len(o.SquareLogoDark.ValueString())))
_, err := base64.StdEncoding.Decode(t, []byte(o.SquareLogoDark.ValueString()))
if err != nil {
diags.AddError("failed to upload square logo (dark)", err.Error())
}
o.sld = t
} else {
o.sld = nil
}
return diags
}
func (o *OrganizationalBrandingLocalization) GetBannerLogoBytes() []byte {
return o.bl
}
func (o *OrganizationalBrandingLocalization) GetBackgroundImageBytes() []byte {
return o.bi
}
func (o *OrganizationalBrandingLocalization) GetSquareLogoLightBytes() []byte {
return o.sll
}
func (o *OrganizationalBrandingLocalization) GetSquareLogoDarkBytes() []byte {
return o.sld
}