-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
GetTableRow, wow, will it even work? No idea! (-:
- Loading branch information
1 parent
2b05bb6
commit 352de7d
Showing
6 changed files
with
163 additions
and
51 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
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,65 @@ | ||
package datasource | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/BESTSELLER/terraform-provider-servicenow-data/internal/client" | ||
"github.com/BESTSELLER/terraform-provider-servicenow-data/internal/resource" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
// TODO | ||
func DatabaseRowDatasource() *schema.Resource { | ||
return &schema.Resource{ | ||
Schema: resource.RowSchema, | ||
ReadContext: dataSourceDatabaseRowRead, | ||
Description: "A row in a SN table", | ||
UseJSONNumber: false, | ||
} | ||
} | ||
|
||
func dataSourceDatabaseRowRead(ctx context.Context, data *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
c := m.(*client.Client) | ||
|
||
rowData := data.Get("row_data").([]interface{}) | ||
|
||
// Warning or errors can be collected in a slice type | ||
var diags diag.Diagnostics | ||
tableID := data.Get("table_id").(string) | ||
if tableID == "" { | ||
diags = append(diags, diag.Diagnostic{ | ||
Severity: diag.Error, | ||
Summary: "tableID is mandatory", | ||
}) | ||
return diags | ||
} | ||
rowID := data.Get("row_data").(map[string]string)["sys_id"] | ||
|
||
if rowID == "" { | ||
diags = append(diags, diag.Diagnostic{ | ||
Severity: diag.Error, | ||
Summary: "sys_id is mandatory", | ||
}) | ||
return diags | ||
} | ||
|
||
order, err := c.GetTableRow(tableID, rowID) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
rowData = parseRowSchema(tableID, order) | ||
if err := data.Set("row_data", rowData); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
data.SetId(fmt.Sprintf("%s/%s", tableID, rowID)) | ||
|
||
return diags | ||
|
||
} | ||
|
||
func parseRowSchema(tableID string, row *map[string]string) []interface{} { | ||
panic("parseRowSchema unimplemented") | ||
} |
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,6 @@ | ||
package models | ||
|
||
type ApprovalItem struct { | ||
Link string `json:"link"` | ||
Value string `json:"value"` | ||
} |
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