Skip to content

Commit

Permalink
feat: introduce tenant_id
Browse files Browse the repository at this point in the history
  • Loading branch information
tchiotludo committed Oct 19, 2023
1 parent 2f04860 commit 96b8c3b
Show file tree
Hide file tree
Showing 34 changed files with 214 additions and 67 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ jobs:
curl "127.27.27.27:9200" > /dev/null
curl -X POST "127.27.27.27:8080/api/v1/users" > /dev/null
curl -u [email protected]:pass -X POST -H 'Content-Type: application/json' -d '{"id":"unit_test","name":"Unit Test"}' "127.27.27.27:8080/api/v1/tenants" > /dev/null
curl -H "Content-Type: application/x-ndjson" -XPOST "127.27.27.27:9200/_bulk?pretty" --data-binary @.github/workflows/index.jsonl
- name: Set up Go
Expand Down
6 changes: 4 additions & 2 deletions docs/data-sources/binding.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,14 @@ data "kestra_binding" "example" {

- `binding_id` (String) The binding id.

### Optional

- `tenant_id` (String) The tenant id.

### Read-Only

- `external_id` (String) The binding external id.
- `id` (String) The ID of this resource.
- `namespace` (String) The linked namespace.
- `role_id` (String) The role id.
- `type` (String) The binding type.


5 changes: 2 additions & 3 deletions docs/data-sources/flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,11 @@ data "kestra_flow" "example" {

### Optional

- `keep_original_source` (Boolean) Use the content as source code, keeping comment and indentation. Defaults to `true`.
- `keep_original_source` (Boolean) Use the content as source code, keeping comment and indentation. Defaults to `false`.
- `tenant_id` (String) The tenant id.

### Read-Only

- `content` (String) The flow content as yaml.
- `id` (String) The ID of this resource.
- `revision` (Number) The flow revision.


3 changes: 1 addition & 2 deletions docs/data-sources/group.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,10 @@ data "kestra_group" "example" {
### Optional

- `namespace` (String) The linked namespace.
- `tenant_id` (String) The tenant id.

### Read-Only

- `description` (String) The group description.
- `id` (String) The ID of this resource.
- `name` (String) The group name.


6 changes: 4 additions & 2 deletions docs/data-sources/namespace.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,13 @@ data "kestra_namespace" "example" {

- `namespace_id` (String) The namespace.

### Optional

- `tenant_id` (String) The tenant id.

### Read-Only

- `description` (String) The namespace friendly description.
- `id` (String) The ID of this resource.
- `task_defaults` (String) The namespace task defaults.
- `variables` (String) The namespace variables.


3 changes: 1 addition & 2 deletions docs/data-sources/role.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ data "kestra_role" "example" {
### Optional

- `namespace` (String) The linked namespace.
- `tenant_id` (String) The tenant id.

### Read-Only

Expand All @@ -43,5 +44,3 @@ Read-Only:

- `permissions` (List of String)
- `type` (String)


6 changes: 4 additions & 2 deletions docs/data-sources/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,11 @@ data "kestra_template" "example" {
- `namespace` (String) The namespace.
- `template_id` (String) The template id.

### Optional

- `tenant_id` (String) The tenant id.

### Read-Only

- `content` (String) The template content as yaml.
- `id` (String) The ID of this resource.


2 changes: 0 additions & 2 deletions docs/data-sources/user.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,3 @@ data "kestra_user" "example" {
- `id` (String) The ID of this resource.
- `last_name` (String) The user last name.
- `username` (String) The user name.


1 change: 1 addition & 0 deletions docs/resources/binding.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ resource "kestra_binding" "example" {
### Optional

- `namespace` (String) The linked namespace.
- `tenant_id` (String) The tenant id.

### Read-Only

Expand Down
3 changes: 1 addition & 2 deletions docs/resources/flow.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ resource "kestra_flow" "example" {
namespace = "io.kestra.mynamespace"
flow_id = "my-flow"
content = <<EOT
id: "my-flow"
namespace: "io.kestra.mynamespace"
inputs:
- name: my-value
type: STRING
Expand Down Expand Up @@ -52,6 +50,7 @@ EOT
### Optional

- `keep_original_source` (Boolean) Use the content as source code, keeping comment and indentation. Defaults to `true`.
- `tenant_id` (String) The tenant id.

### Read-Only

Expand Down
1 change: 1 addition & 0 deletions docs/resources/group.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ resource "kestra_group" "example" {

- `description` (String) The group description.
- `namespace` (String) The linked namespace.
- `tenant_id` (String) The tenant id.

### Read-Only

Expand Down
1 change: 1 addition & 0 deletions docs/resources/namespace.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ EOT

- `description` (String) The namespace friendly description.
- `task_defaults` (String) The namespace task defaults in yaml string.
- `tenant_id` (String) The tenant id.
- `variables` (String) The namespace variables in yaml string.

### Read-Only
Expand Down
6 changes: 4 additions & 2 deletions docs/resources/namespace_secret.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,10 @@ resource "kestra_namespace_secret" "example" {
- `secret_key` (String) The namespace secrey key.
- `secret_value` (String, Sensitive) The namespace secrey value.

### Read-Only
### Optional

- `id` (String) The ID of this resource.
- `tenant_id` (String) The tenant id.

### Read-Only

- `id` (String) The ID of this resource.
1 change: 1 addition & 0 deletions docs/resources/role.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ resource "kestra_role" "example" {
- `description` (String) The role description.
- `namespace` (String) The linked namespace.
- `permissions` (Block Set) The role permissions. (see [below for nested schema](#nestedblock--permissions))
- `tenant_id` (String) The tenant id.

### Read-Only

Expand Down
4 changes: 4 additions & 0 deletions docs/resources/template.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ EOT
- `namespace` (String) The template namespace.
- `template_id` (String) The template id.

### Optional

- `tenant_id` (String) The tenant id.

### Read-Only

- `id` (String) The ID of this resource.
Expand Down
2 changes: 0 additions & 2 deletions docs/resources/user_password.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,3 @@ resource "kestra_user_password" "example" {
### Read-Only

- `id` (String) The ID of this resource.


8 changes: 7 additions & 1 deletion internal/provider/data_source_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ func dataSourceBinding() *schema.Resource {

ReadContext: dataSourceBindingRead,
Schema: map[string]*schema.Schema{
"tenant_id": {
Description: "The tenant id.",
Type: schema.TypeString,
Optional: true,
},
"binding_id": {
Description: "The binding id.",
Type: schema.TypeString,
Expand Down Expand Up @@ -48,8 +53,9 @@ func dataSourceBindingRead(ctx context.Context, d *schema.ResourceData, meta int
var diags diag.Diagnostics

bindingId := d.Get("binding_id").(string)
tenantId := d.Get("tenant_id").(string)

r, reqErr := c.request("GET", fmt.Sprintf("/api/v1/bindings/%s", bindingId), nil)
r, reqErr := c.request("GET", fmt.Sprintf("%s/bindings/%s", apiRoot(tenantId), bindingId), nil)
if reqErr != nil {
return diag.FromErr(reqErr.Err)
}
Expand Down
12 changes: 9 additions & 3 deletions internal/provider/data_source_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ func dataSourceFlow() *schema.Resource {

ReadContext: dataSourceFlowRead,
Schema: map[string]*schema.Schema{
"tenant_id": {
Description: "The tenant id.",
Type: schema.TypeString,
Optional: true,
},
"namespace": {
Description: "The namespace.",
Type: schema.TypeString,
Expand Down Expand Up @@ -48,10 +53,11 @@ func dataSourceFlowRead(ctx context.Context, d *schema.ResourceData, meta interf
c := meta.(*Client)
var diags diag.Diagnostics

namespaceId := d.Get("namespace")
flowId := d.Get("flow_id")
namespaceId := d.Get("namespace").(string)
flowId := d.Get("flow_id").(string)
tenantId := d.Get("tenant_id").(string)

r, reqErr := c.request("GET", fmt.Sprintf("/api/v1/flows/%s/%s", namespaceId, flowId), nil)
r, reqErr := c.request("GET", fmt.Sprintf("%s/flows/%s/%s", apiRoot(tenantId), namespaceId, flowId), nil)
if reqErr != nil {
return diag.FromErr(reqErr.Err)
}
Expand Down
8 changes: 7 additions & 1 deletion internal/provider/data_source_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ func dataSourceGroup() *schema.Resource {

ReadContext: dataSourceGroupRead,
Schema: map[string]*schema.Schema{
"tenant_id": {
Description: "The tenant id.",
Type: schema.TypeString,
Optional: true,
},
"group_id": {
Description: "The group.",
Type: schema.TypeString,
Expand Down Expand Up @@ -43,8 +48,9 @@ func dataSourceGroupRead(ctx context.Context, d *schema.ResourceData, meta inter
var diags diag.Diagnostics

groupId := d.Get("group_id").(string)
tenantId := d.Get("tenant_id").(string)

r, reqErr := c.request("GET", fmt.Sprintf("/api/v1/groups/%s", groupId), nil)
r, reqErr := c.request("GET", fmt.Sprintf("%s/groups/%s", apiRoot(tenantId), groupId), nil)
if reqErr != nil {
return diag.FromErr(reqErr.Err)
}
Expand Down
8 changes: 7 additions & 1 deletion internal/provider/data_source_namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ func dataSourceNamespace() *schema.Resource {

ReadContext: dataSourceNamespaceRead,
Schema: map[string]*schema.Schema{
"tenant_id": {
Description: "The tenant id.",
Type: schema.TypeString,
Optional: true,
},
"namespace_id": {
Description: "The namespace.",
Type: schema.TypeString,
Expand Down Expand Up @@ -43,8 +48,9 @@ func dataSourceNamespaceRead(ctx context.Context, d *schema.ResourceData, meta i
var diags diag.Diagnostics

namespaceId := d.Get("namespace_id").(string)
tenantId := d.Get("tenant_id").(string)

r, reqErr := c.request("GET", fmt.Sprintf("/api/v1/namespaces/%s", namespaceId), nil)
r, reqErr := c.request("GET", fmt.Sprintf("%s/namespaces/%s", apiRoot(tenantId), namespaceId), nil)
if reqErr != nil {
return diag.FromErr(reqErr.Err)
}
Expand Down
8 changes: 7 additions & 1 deletion internal/provider/data_source_role.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ func dataSourceRole() *schema.Resource {

ReadContext: dataSourceRoleRead,
Schema: map[string]*schema.Schema{
"tenant_id": {
Description: "The tenant id.",
Type: schema.TypeString,
Optional: true,
},
"role_id": {
Description: "The role.",
Type: schema.TypeString,
Expand Down Expand Up @@ -63,8 +68,9 @@ func dataSourceRoleRead(ctx context.Context, d *schema.ResourceData, meta interf
var diags diag.Diagnostics

roleId := d.Get("role_id").(string)
tenantId := d.Get("tenant_id").(string)

r, reqErr := c.request("GET", fmt.Sprintf("/api/v1/roles/%s", roleId), nil)
r, reqErr := c.request("GET", fmt.Sprintf("%s/roles/%s", apiRoot(tenantId), roleId), nil)
if reqErr != nil {
return diag.FromErr(reqErr.Err)
}
Expand Down
12 changes: 9 additions & 3 deletions internal/provider/data_source_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ func dataSourceTemplate() *schema.Resource {

ReadContext: dataSourceTemplateRead,
Schema: map[string]*schema.Schema{
"tenant_id": {
Description: "The tenant id.",
Type: schema.TypeString,
Optional: true,
},
"namespace": {
Description: "The namespace.",
Type: schema.TypeString,
Expand All @@ -37,10 +42,11 @@ func dataSourceTemplateRead(ctx context.Context, d *schema.ResourceData, meta in
c := meta.(*Client)
var diags diag.Diagnostics

namespaceId := d.Get("namespace")
templateId := d.Get("template_id")
namespaceId := d.Get("namespace").(string)
templateId := d.Get("template_id").(string)
tenantId := d.Get("tenant_id").(string)

r, reqErr := c.request("GET", fmt.Sprintf("/api/v1/templates/%s/%s", namespaceId, templateId), nil)
r, reqErr := c.request("GET", fmt.Sprintf("%s/templates/%s/%s", apiRoot(tenantId), namespaceId, templateId), nil)
if reqErr != nil {
return diag.FromErr(reqErr.Err)
}
Expand Down
2 changes: 1 addition & 1 deletion internal/provider/data_source_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func dataSourceUserRead(ctx context.Context, d *schema.ResourceData, meta interf

userId := d.Get("user_id").(string)

r, reqErr := c.request("GET", fmt.Sprintf("/api/v1/users/%s", userId), nil)
r, reqErr := c.request("GET", fmt.Sprintf("%s/users/%s", apiRoot(""), userId), nil)
if reqErr != nil {
return diag.FromErr(reqErr.Err)
}
Expand Down
8 changes: 8 additions & 0 deletions internal/provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,3 +177,11 @@ func pointerToString(s *string) string {
}
return *s
}

func apiRoot(tenantId string) string {
if tenantId == "" {
return "/api/v1"
}

return fmt.Sprintf("/api/v1/%s", tenantId)
}
16 changes: 13 additions & 3 deletions internal/provider/resource_binding.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ func resourceBinding() *schema.Resource {
ReadContext: resourceBindingRead,
DeleteContext: resourceBindingDelete,
Schema: map[string]*schema.Schema{
"tenant_id": {
Description: "The tenant id.",
Type: schema.TypeString,
Optional: true,
ForceNew: true,
},
"type": {
Description: "The binding type.",
Type: schema.TypeString,
Expand Down Expand Up @@ -56,7 +62,9 @@ func resourceBindingCreate(ctx context.Context, d *schema.ResourceData, meta int
return diag.FromErr(err)
}

r, reqErr := c.request("POST", "/api/v1/bindings", body)
tenantId := d.Get("tenant_id").(string)

r, reqErr := c.request("POST", fmt.Sprintf("%s/bindings", apiRoot(tenantId)), body)
if reqErr != nil {
return diag.FromErr(reqErr.Err)
}
Expand All @@ -74,8 +82,9 @@ func resourceBindingRead(ctx context.Context, d *schema.ResourceData, meta inter
var diags diag.Diagnostics

bindingId := d.Id()
tenantId := d.Get("tenant_id").(string)

r, reqErr := c.request("GET", fmt.Sprintf("/api/v1/bindings/%s", bindingId), nil)
r, reqErr := c.request("GET", fmt.Sprintf("%s/bindings/%s", apiRoot(tenantId), bindingId), nil)
if reqErr != nil {
if reqErr.StatusCode == http.StatusNotFound {
d.SetId("")
Expand All @@ -98,8 +107,9 @@ func resourceBindingDelete(ctx context.Context, d *schema.ResourceData, meta int
var diags diag.Diagnostics

bindingId := d.Id()
tenantId := d.Get("tenant_id").(string)

_, reqErr := c.request("DELETE", fmt.Sprintf("/api/v1/bindings/%s", bindingId), nil)
_, reqErr := c.request("DELETE", fmt.Sprintf("%s/bindings/%s", apiRoot(tenantId), bindingId), nil)
if reqErr != nil {
return diag.FromErr(reqErr.Err)
}
Expand Down
Loading

0 comments on commit 96b8c3b

Please sign in to comment.