-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Arthur Outhenin-Chalandre <arthur.outhenin-chalandre@cern.ch>
- Loading branch information
1 parent
6065bf9
commit 4ee4809
Showing
6 changed files
with
126 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
package ceph | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceAuth() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourceAuthRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"entity": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
ForceNew: true, | ||
Description: "The entity name (i.e.: client.admin)", | ||
}, | ||
|
||
"caps": { | ||
Type: schema.TypeMap, | ||
Elem: &schema.Schema{ | ||
Type: schema.TypeString, | ||
}, | ||
Computed: true, | ||
Description: "The caps of the entity", | ||
}, | ||
|
||
"keyring": { | ||
Type: schema.TypeString, | ||
|
||
Computed: true, | ||
Description: "The cephx keyring of the entity", | ||
}, | ||
|
||
"key": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: "The cephx key of the entity", | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceAuthRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
conn, err := meta.(*Config).GetCephConnection() | ||
if err != nil { | ||
return diag.Errorf("Unable to connect to Ceph: %s", err) | ||
} | ||
entity := d.Get("entity").(string) | ||
|
||
command, err := json.Marshal(map[string]interface{}{ | ||
"prefix": "auth get", | ||
"format": "json", | ||
"entity": entity, | ||
}) | ||
if err != nil { | ||
return diag.Errorf("Error data_source_auth unable to create get JSON command: %s", err) | ||
} | ||
|
||
buf, _, err := conn.MonCommand(command) | ||
if err != nil { | ||
return diag.Errorf("Error data_source_auth on get command: %s", err) | ||
} | ||
|
||
var authResponses []authResponse | ||
err = json.Unmarshal(buf, &authResponses) | ||
if err != nil { | ||
return diag.Errorf("Error data_source auth unmarshal on response: %s", err) | ||
} | ||
|
||
d.SetId(entity) | ||
return setAuthResourceData(d, authResponses) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
--- | ||
# generated by https://github.com/hashicorp/terraform-plugin-docs | ||
page_title: "ceph_auth Data Source - terraform-provider-ceph" | ||
subcategory: "" | ||
description: |- | ||
--- | ||
|
||
# ceph_auth (Data Source) | ||
|
||
|
||
|
||
|
||
|
||
<!-- schema generated by tfplugindocs --> | ||
## Schema | ||
|
||
### Required | ||
|
||
- `entity` (String) The entity name (i.e.: client.admin) | ||
|
||
### Read-Only | ||
|
||
- `caps` (Map of String) The caps of the entity | ||
- `id` (String) The ID of this resource. | ||
- `key` (String) The cephx key of the entity | ||
- `keyring` (String) The cephx keyring of the entity | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters