generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 40
/
data_source_current_user.go
112 lines (104 loc) · 3.09 KB
/
data_source_current_user.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
package user
import (
"context"
"github.com/harness/terraform-provider-harness/helpers"
"github.com/harness/terraform-provider-harness/internal"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func DataSourceCurrentUser() *schema.Resource {
return &schema.Resource{
Description: "Data source for retrieving the current user based on the API key.",
ReadContext: dataSourceCurrentUserRead,
Schema: map[string]*schema.Schema{
"uuid": {
Description: "Unique identifier of the user.",
Type: schema.TypeString,
Computed: true,
},
"name": {
Description: "Name of the user.",
Type: schema.TypeString,
Computed: true,
},
"email": {
Description: "Email address of the user.",
Type: schema.TypeString,
Computed: true,
},
"token": {
Description: "Token used to authenticate the user.",
Type: schema.TypeString,
Computed: true,
},
"default_account_id": {
Description: "Default account ID of the user.",
Type: schema.TypeString,
Computed: true,
},
"intent": {
Description: "Intent of the user.",
Type: schema.TypeString,
Computed: true,
},
"admin": {
Description: "Whether the user is an administrator.",
Type: schema.TypeBool,
Computed: true,
},
"is_two_factor_auth_enabled": {
Description: "Whether 2FA is enabled for the user.",
Type: schema.TypeBool,
Computed: true,
},
"email_verified": {
Description: "Whether the user's email address has been verified.",
Type: schema.TypeBool,
Computed: true,
},
"locked": {
Description: "Whether or not the user account is locked.",
Type: schema.TypeBool,
Computed: true,
},
"signup_action": {
Description: "Signup action of the user.",
Type: schema.TypeString,
Computed: true,
},
"edition": {
Description: "Edition of the platform being used.",
Type: schema.TypeString,
Computed: true,
},
"billing_frequency": {
Description: "Billing frequency of the user.",
Type: schema.TypeString,
Computed: true,
},
},
}
}
func dataSourceCurrentUserRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
c, ctx := meta.(*internal.Session).GetPlatformClientWithContext(ctx)
resp, httpResp, err := c.UserApi.GetCurrentUserInfo(ctx, c.AccountId)
if err != nil {
return helpers.HandleApiError(err, d, httpResp)
}
user := resp.Data
d.SetId(user.Uuid)
d.Set("uuid", user.Uuid)
d.Set("name", user.Name)
d.Set("email", user.Email)
d.Set("token", user.Token)
d.Set("default_account_id", user.DefaultAccountId)
d.Set("intent", user.Intent)
d.Set("admin", user.Admin)
d.Set("is_two_factor_auth_enabled", user.TwoFactorAuthenticationEnabled)
d.Set("email_verified", user.EmailVerified)
d.Set("locked", user.Locked)
d.Set("signup_action", user.SignupAction)
d.Set("edition", user.Edition)
d.Set("billing_frequency", user.BillingFrequency)
return nil
}