Skip to content

Commit dd8c288

Browse files
cvhariharanThunderbottom
authored andcommitted
feat: support name based searches in data sources
1 parent 2ca7d22 commit dd8c288

File tree

9 files changed

+246
-116
lines changed

9 files changed

+246
-116
lines changed

docs/data-sources/role.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Retrieves information about a specific role in WarpGate.
1414
```hcl
1515
data "warpgate_role" "developers" {
1616
id = "12345678-1234-1234-1234-123456789012"
17+
// optionally
18+
// name = "developers"
1719
}
1820
1921
output "role_name" {
@@ -31,16 +33,20 @@ resource "warpgate_user_role" "eugene_developer" {
3133

3234
The following arguments are supported:
3335

34-
* `id` - (Required) The ID of the role to look up.
36+
- `id` - The ID of the role to look up.
37+
- `name` - The name of the role to look up.
38+
39+
Either `id` or `name` should be specified.
3540

3641
## Attribute Reference
3742

3843
In addition to the arguments listed above, the following attributes are exported:
3944

40-
* `name` - The name of the role.
41-
* `description` - The description of the role.
45+
- `name` - The name of the role.
46+
- `description` - The description of the role.
4247

4348
<!-- schema generated by tfplugindocs -->
49+
4450
## Schema
4551

4652
### Required

docs/data-sources/target.md

Lines changed: 59 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Retrieves information about a specific target in Warpgate. This data source allo
1414
```hcl
1515
data "warpgate_target" "web_server" {
1616
id = "12345678-1234-1234-1234-123456789012"
17+
// optionally
18+
// name = "webserver"
1719
}
1820
1921
output "target_name" {
@@ -42,20 +44,20 @@ locals {
4244
is_http = length(data.warpgate_target.server.http_options) > 0
4345
is_mysql = length(data.warpgate_target.server.mysql_options) > 0
4446
is_postgres = length(data.warpgate_target.server.postgres_options) > 0
45-
47+
4648
# Safely access target details
4749
host = local.is_ssh ? data.warpgate_target.server.ssh_options[0].host :
4850
local.is_http ? "<HTTP target>" :
4951
local.is_mysql ? data.warpgate_target.server.mysql_options[0].host :
50-
local.is_postgres ? data.warpgate_target.server.postgres_options[0].host :
52+
local.is_postgres ? data.warpgate_target.server.postgres_options[0].host :
5153
"unknown"
5254
}
5355
5456
output "target_type" {
55-
value = local.is_ssh ? "SSH" :
56-
local.is_http ? "HTTP" :
57-
local.is_mysql ? "MySQL" :
58-
local.is_postgres ? "PostgreSQL" :
57+
value = local.is_ssh ? "SSH" :
58+
local.is_http ? "HTTP" :
59+
local.is_mysql ? "MySQL" :
60+
local.is_postgres ? "PostgreSQL" :
5961
"unknown"
6062
}
6163
@@ -68,54 +70,58 @@ output "target_host" {
6870

6971
The following arguments are supported:
7072

71-
* `id` - (Required) The ID of the target to look up.
73+
- `id` - The ID of the target to look up.
74+
- `name` - The name of the target to look up.
75+
76+
Either `id` or `name` should be specified.
7277

7378
## Attribute Reference
7479

7580
In addition to the arguments listed above, the following attributes are exported:
7681

77-
* `name` - The name of the target.
78-
* `description` - The description of the target.
79-
* `allow_roles` - The list of roles allowed to access this target.
82+
- `name` - The name of the target.
83+
- `description` - The description of the target.
84+
- `allow_roles` - The list of roles allowed to access this target.
8085

8186
Based on the target type, one of the following option blocks will be populated:
8287

83-
* `ssh_options` - Configuration for SSH targets.
84-
* `host` - The SSH server hostname or IP address.
85-
* `port` - The SSH server port.
86-
* `username` - The SSH username.
87-
* `allow_insecure_algos` - Whether insecure SSH algorithms are allowed.
88-
* `password_auth` - Password authentication configuration (if applicable).
89-
* `password` - The password for SSH authentication.
90-
* `public_key_auth` - Public key authentication configuration (if applicable).
91-
92-
* `http_options` - Configuration for HTTP targets.
93-
* `url` - The HTTP server URL.
94-
* `tls` - TLS configuration.
95-
* `mode` - TLS mode (Disabled, Preferred, Required).
96-
* `verify` - Whether TLS certificates are verified.
97-
* `headers` - HTTP headers included in requests.
98-
* `external_host` - External host for HTTP requests.
99-
100-
* `mysql_options` - Configuration for MySQL targets.
101-
* `host` - The MySQL server hostname or IP address.
102-
* `port` - The MySQL server port.
103-
* `username` - The MySQL username.
104-
* `password` - The MySQL password.
105-
* `tls` - TLS configuration.
106-
* `mode` - TLS mode (Disabled, Preferred, Required).
107-
* `verify` - Whether TLS certificates are verified.
108-
109-
* `postgres_options` - Configuration for PostgreSQL targets.
110-
* `host` - The PostgreSQL server hostname or IP address.
111-
* `port` - The PostgreSQL server port.
112-
* `username` - The PostgreSQL username.
113-
* `password` - The PostgreSQL password.
114-
* `tls` - TLS configuration.
115-
* `mode` - TLS mode (Disabled, Preferred, Required).
116-
* `verify` - Whether TLS certificates are verified.
88+
- `ssh_options` - Configuration for SSH targets.
89+
- `host` - The SSH server hostname or IP address.
90+
- `port` - The SSH server port.
91+
- `username` - The SSH username.
92+
- `allow_insecure_algos` - Whether insecure SSH algorithms are allowed.
93+
- `password_auth` - Password authentication configuration (if applicable).
94+
- `password` - The password for SSH authentication.
95+
- `public_key_auth` - Public key authentication configuration (if applicable).
96+
97+
- `http_options` - Configuration for HTTP targets.
98+
- `url` - The HTTP server URL.
99+
- `tls` - TLS configuration.
100+
- `mode` - TLS mode (Disabled, Preferred, Required).
101+
- `verify` - Whether TLS certificates are verified.
102+
- `headers` - HTTP headers included in requests.
103+
- `external_host` - External host for HTTP requests.
104+
105+
- `mysql_options` - Configuration for MySQL targets.
106+
- `host` - The MySQL server hostname or IP address.
107+
- `port` - The MySQL server port.
108+
- `username` - The MySQL username.
109+
- `password` - The MySQL password.
110+
- `tls` - TLS configuration.
111+
- `mode` - TLS mode (Disabled, Preferred, Required).
112+
- `verify` - Whether TLS certificates are verified.
113+
114+
- `postgres_options` - Configuration for PostgreSQL targets.
115+
- `host` - The PostgreSQL server hostname or IP address.
116+
- `port` - The PostgreSQL server port.
117+
- `username` - The PostgreSQL username.
118+
- `password` - The PostgreSQL password.
119+
- `tls` - TLS configuration.
120+
- `mode` - TLS mode (Disabled, Preferred, Required).
121+
- `verify` - Whether TLS certificates are verified.
117122

118123
<!-- schema generated by tfplugindocs -->
124+
119125
## Schema
120126

121127
### Required
@@ -133,6 +139,7 @@ Based on the target type, one of the following option blocks will be populated:
133139
- `ssh_options` (List of Object) SSH target options (see [below for nested schema](#nestedatt--ssh_options))
134140

135141
<a id="nestedatt--http_options"></a>
142+
136143
### Nested Schema for `http_options`
137144

138145
Read-Only:
@@ -143,16 +150,16 @@ Read-Only:
143150
- `url` (String)
144151

145152
<a id="nestedobjatt--http_options--tls"></a>
153+
146154
### Nested Schema for `http_options.tls`
147155

148156
Read-Only:
149157

150158
- `mode` (String)
151159
- `verify` (Boolean)
152160

153-
154-
155161
<a id="nestedatt--mysql_options"></a>
162+
156163
### Nested Schema for `mysql_options`
157164

158165
Read-Only:
@@ -164,16 +171,16 @@ Read-Only:
164171
- `username` (String)
165172

166173
<a id="nestedobjatt--mysql_options--tls"></a>
174+
167175
### Nested Schema for `mysql_options.tls`
168176

169177
Read-Only:
170178

171179
- `mode` (String)
172180
- `verify` (Boolean)
173181

174-
175-
176182
<a id="nestedatt--postgres_options"></a>
183+
177184
### Nested Schema for `postgres_options`
178185

179186
Read-Only:
@@ -185,16 +192,16 @@ Read-Only:
185192
- `username` (String)
186193

187194
<a id="nestedobjatt--postgres_options--tls"></a>
195+
188196
### Nested Schema for `postgres_options.tls`
189197

190198
Read-Only:
191199

192200
- `mode` (String)
193201
- `verify` (Boolean)
194202

195-
196-
197203
<a id="nestedatt--ssh_options"></a>
204+
198205
### Nested Schema for `ssh_options`
199206

200207
Read-Only:
@@ -207,14 +214,15 @@ Read-Only:
207214
- `username` (String)
208215

209216
<a id="nestedobjatt--ssh_options--password_auth"></a>
217+
210218
### Nested Schema for `ssh_options.password_auth`
211219

212220
Read-Only:
213221

214222
- `password` (String)
215223

216-
217224
<a id="nestedobjatt--ssh_options--public_key_auth"></a>
225+
218226
### Nested Schema for `ssh_options.public_key_auth`
219227

220228
Read-Only:

docs/data-sources/user.md

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Retrieves information about a specific user in WarpGate.
1414
```hcl
1515
data "warpgate_user" "eugene" {
1616
id = "12345678-1234-1234-1234-123456789012"
17+
// optionally
18+
// username = "eugene"
1719
}
1820
1921
output "username" {
@@ -45,23 +47,26 @@ locals {
4547

4648
The following arguments are supported:
4749

48-
* `id` - (Required) The ID of the user to look up.
50+
- `id` - The ID of the user to look up.
51+
- `username` - The username of the user to look up
52+
53+
Either `id` or `username` should be specified.
4954

5055
## Attribute Reference
5156

5257
In addition to the arguments listed above, the following attributes are exported:
5358

54-
* `username` - The username of the user.
55-
* `description` - The description of the user.
56-
* `credential_policy` - The credential policy for the user. This is a list with a single element.
57-
* `http` - List of credential types required for HTTP access.
58-
* `ssh` - List of credential types required for SSH access.
59-
* `mysql` - List of credential types required for MySQL access.
60-
* `postgres` - List of credential types required for PostgreSQL access.
61-
* `sso_credentials` - List of SSO credentials associated with the user.
62-
* `id` - The ID of the SSO credential.
63-
* `sso_provider` - The SSO provider name (e.g., 'google', 'github', 'okta').
64-
* `email` - The email address associated with the SSO provider.
59+
- `username` - The username of the user.
60+
- `description` - The description of the user.
61+
- `credential_policy` - The credential policy for the user. This is a list with a single element.
62+
- `http` - List of credential types required for HTTP access.
63+
- `ssh` - List of credential types required for SSH access.
64+
- `mysql` - List of credential types required for MySQL access.
65+
- `postgres` - List of credential types required for PostgreSQL access.
66+
- `sso_credentials` - List of SSO credentials associated with the user.
67+
- `id` - The ID of the SSO credential.
68+
- `sso_provider` - The SSO provider name (e.g., 'google', 'github', 'okta').
69+
- `email` - The email address associated with the SSO provider.
6570

6671
## Working with Credential Policies
6772

@@ -91,6 +96,7 @@ locals {
9196
```
9297

9398
<!-- schema generated by tfplugindocs -->
99+
94100
## Schema
95101

96102
### Required
@@ -105,6 +111,7 @@ locals {
105111
- `username` (String) The username of the user
106112

107113
<a id="nestedatt--credential_policy"></a>
114+
108115
### Nested Schema for `credential_policy`
109116

110117
Read-Only:
@@ -115,6 +122,7 @@ Read-Only:
115122
- `ssh` (List of String)
116123

117124
<a id="nestedatt--sso_credentials"></a>
125+
118126
### Nested Schema for `sso_credentials`
119127

120128
Read-Only:

internal/client/role.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,14 @@ type RoleCreateRequest struct {
2424
// the provided search term.
2525
func (c *Client) GetRoles(ctx context.Context, search string) ([]Role, error) {
2626
path := "/roles"
27-
if search != "" {
28-
path = fmt.Sprintf("%s?search=%s", path, search)
27+
28+
req, err := http.NewRequest(http.MethodGet, path, nil)
29+
if err != nil {
30+
return nil, err
2931
}
32+
req.URL.Query().Add("search", search)
3033

31-
resp, err := c.doRequest(ctx, http.MethodGet, path, nil)
34+
resp, err := c.doRequest(ctx, http.MethodGet, req.URL.Path, nil)
3235
if err != nil {
3336
return nil, err
3437
}

internal/client/target.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,11 +101,13 @@ type TargetDataRequest struct {
101101
// the provided search term.
102102
func (c *Client) GetTargets(ctx context.Context, search string) ([]Target, error) {
103103
path := "/targets"
104-
if search != "" {
105-
path = fmt.Sprintf("%s?search=%s", path, search)
104+
req, err := http.NewRequest(http.MethodGet, path, nil)
105+
if err != nil {
106+
return nil, err
106107
}
108+
req.URL.Query().Add("search", search)
107109

108-
resp, err := c.doRequest(ctx, http.MethodGet, path, nil)
110+
resp, err := c.doRequest(ctx, http.MethodGet, req.URL.Path, nil)
109111
if err != nil {
110112
return nil, err
111113
}

internal/client/user.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,14 @@ type UserUpdateRequest struct {
5858
// the provided search term.
5959
func (c *Client) GetUsers(ctx context.Context, search string) ([]User, error) {
6060
path := "/users"
61-
if search != "" {
62-
path = fmt.Sprintf("%s?search=%s", path, search)
61+
62+
req, err := http.NewRequest(http.MethodGet, path, nil)
63+
if err != nil {
64+
return nil, err
6365
}
66+
req.URL.Query().Add("search", search)
6467

65-
resp, err := c.doRequest(ctx, http.MethodGet, path, nil)
68+
resp, err := c.doRequest(ctx, http.MethodGet, req.URL.Path, nil)
6669
if err != nil {
6770
return nil, err
6871
}

0 commit comments

Comments
 (0)