generated from SAP/repository-template
/
type_directory_role.go
67 lines (53 loc) · 2.46 KB
/
type_directory_role.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
package provider
import (
"context"
"github.com/SAP/terraform-provider-btp/internal/btpcli/types/xsuaa_authz"
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/types"
)
type directoryRoleScope struct {
Name types.String `tfsdk:"name"`
Description types.String `tfsdk:"description"`
CustomGrantAsAuthorityToApps types.Set `tfsdk:"custom_grant_as_authority_to_apps"`
CustomGrantedApps types.Set `tfsdk:"custom_granted_apps"`
GrantAsAuthorityToApps types.Set `tfsdk:"grant_as_authority_to_apps"`
GrantedApps types.Set `tfsdk:"granted_apps"`
}
type directoryRoleType struct {
/* INPUT */
DirectoryId types.String `tfsdk:"directory_id"`
Id types.String `tfsdk:"id"`
Name types.String `tfsdk:"name"`
RoleTemplateAppId types.String `tfsdk:"app_id"`
RoleTemplateName types.String `tfsdk:"role_template_name"`
/* OUTPUT */
Description types.String `tfsdk:"description"`
IsReadOnly types.Bool `tfsdk:"read_only"`
Scopes []directoryRoleScope `tfsdk:"scopes"`
}
func directoryRoleFromValue(ctx context.Context, value xsuaa_authz.Role) (directoryRoleType, diag.Diagnostics) {
var dirRole directoryRoleType
dirRole.Description = types.StringValue(value.Description)
dirRole.IsReadOnly = types.BoolValue(value.IsReadOnly)
dirRole.Name = types.StringValue(value.Name)
dirRole.RoleTemplateName = types.StringValue(value.RoleTemplateName)
dirRole.RoleTemplateAppId = types.StringValue(value.RoleTemplateAppId)
dirRole.Scopes = []directoryRoleScope{}
var summary, diags diag.Diagnostics
for _, scope := range value.Scopes {
scopeVal := directoryRoleScope{
Name: types.StringValue(scope.Name),
Description: types.StringValue(scope.Description),
}
scopeVal.CustomGrantAsAuthorityToApps, diags = types.SetValueFrom(ctx, types.StringType, scope.CustomGrantAsAuthorityToApps)
summary.Append(diags...)
scopeVal.CustomGrantedApps, diags = types.SetValueFrom(ctx, types.StringType, scope.CustomGrantedApps)
summary.Append(diags...)
scopeVal.GrantAsAuthorityToApps, diags = types.SetValueFrom(ctx, types.StringType, scope.GrantAsAuthorityToApps)
summary.Append(diags...)
scopeVal.GrantedApps, diags = types.SetValueFrom(ctx, types.StringType, scope.GrantedApps)
summary.Append(diags...)
dirRole.Scopes = append(dirRole.Scopes, scopeVal)
}
return dirRole, summary
}