/
brand.go
82 lines (73 loc) · 2.13 KB
/
brand.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
package okta
import (
"context"
"encoding/json"
"errors"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/okta/okta-sdk-golang/v4/okta"
)
var brandDataSourceSchema = map[string]*schema.Schema{
"id": {
Type: schema.TypeString,
Computed: true,
Description: "The ID of the Brand",
},
"name": {
Type: schema.TypeString,
Computed: true,
Description: "Brand name",
},
"custom_privacy_policy_url": {
Type: schema.TypeString,
Computed: true,
Description: "Custom privacy policy URL",
},
"links": {
Type: schema.TypeString,
Computed: true,
Description: "Link relations for this object - JSON HAL - Discoverable resources related to the brand",
},
"remove_powered_by_okta": {
Type: schema.TypeBool,
Computed: true,
Description: `Removes "Powered by Okta" from the Okta-hosted sign-in page and "© 2021 Okta, Inc." from the Okta End-User Dashboard`,
},
}
var brandsDataSourceSchema = map[string]*schema.Schema{
"brands": {
Type: schema.TypeSet,
Computed: true,
Description: "List of `okta_brand` belonging to the organization",
Elem: &schema.Resource{
Schema: brandDataSourceSchema,
},
},
}
func flattenBrand(brand *okta.BrandWithEmbedded) map[string]interface{} {
attrs := map[string]interface{}{}
attrs["id"] = brand.GetId()
attrs["custom_privacy_policy_url"] = ""
if brand.GetCustomPrivacyPolicyUrl() != "" {
attrs["custom_privacy_policy_url"] = brand.GetCustomPrivacyPolicyUrl()
}
attrs["name"] = brand.GetName()
links, _ := json.Marshal(brand.GetLinks())
attrs["links"] = string(links)
attrs["remove_powered_by_okta"] = false
if brand.RemovePoweredByOkta != nil {
attrs["remove_powered_by_okta"] = brand.GetRemovePoweredByOkta()
}
return attrs
}
func getDefaultBrand(ctx context.Context, m interface{}) (*okta.BrandWithEmbedded, error) {
brands, _, err := getOktaV3ClientFromMetadata(m).CustomizationAPI.ListBrands(ctx).Execute()
if err != nil {
return nil, err
}
for _, brand := range brands {
if brand.GetIsDefault() {
return &brand, nil
}
}
return nil, errors.New("failed to get default brand")
}