-
Notifications
You must be signed in to change notification settings - Fork 164
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(live): add a new datasource to query record callback configurat…
…ions
- Loading branch information
Showing
4 changed files
with
363 additions
and
5 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,66 @@ | ||
--- | ||
subcategory: "Live" | ||
layout: "huaweicloud" | ||
page_title: "HuaweiCloud: huaweicloud_live_record_callbacks" | ||
description: |- | ||
Use this data source to get a list of the Live record callback configurations. | ||
--- | ||
|
||
# huaweicloud_live_record_callbacks | ||
|
||
Use this data source to get a list of the Live record callback configurations. | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
resource "huaweicloud_live_record_callbacks" "test" { | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `region` - (Optional, String) Specifies the region in which to query the resource. | ||
If omitted, the provider-level region will be used. | ||
|
||
* `domain_name` - (Optional, String) Specifies the ingest domain name. | ||
|
||
* `app_name` - (Optional, String) Specifies the application name. | ||
To match all applications, set this parameter to a wildcard character *****. | ||
Exact application matching is preferred. If no application is matched, all applications will be matched. | ||
|
||
## Attribute Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - The data source ID. | ||
|
||
* `callbacks` - The callback configurations. | ||
|
||
The [callbacks](#callbacks_struct) structure is documented below. | ||
|
||
<a name="callbacks_struct"></a> | ||
The `callbacks` block supports: | ||
|
||
* `sign_type` - The encryption type. Contains the following values: | ||
+ **HMACSHA256** | ||
+ **MD5** | ||
|
||
* `created_at` - The creation time in the format of **yyyy-mm-ddThh:mm:ssZ** (UTC time). | ||
|
||
* `updated_at` - The latest modification time in the format of **yyyy-mm-ddThh:mm:ssZ** (UTC time). | ||
|
||
* `id` - The recording callback ID. | ||
|
||
* `domain_name` - The ingest domain name. | ||
|
||
* `app_name` - The application name. | ||
|
||
* `url` - The callback URL for sending recording notifications. | ||
|
||
* `types` - The types of recording notifications. Contains the following values: | ||
+ **RECORD_NEW_FILE_START**: Recording started. | ||
+ **RECORD_FILE_COMPLETE**: Recording file generated. | ||
+ **RECORD_OVER**: Recording completed. | ||
+ **RECORD_FAILED**: Recording failed. |
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
122 changes: 122 additions & 0 deletions
122
huaweicloud/services/acceptance/live/data_source_huaweicloud_live_record_callbacks_test.go
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,122 @@ | ||
package live | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" | ||
|
||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/services/acceptance" | ||
) | ||
|
||
func TestAccDataSourceRecordCallbacks_basic(t *testing.T) { | ||
var ( | ||
dataSource = "data.huaweicloud_live_record_callbacks.test" | ||
dc = acceptance.InitDataSourceCheck(dataSource) | ||
|
||
byDomainName = "data.huaweicloud_live_record_callbacks.filter_by_domain_name" | ||
dcByDomainName = acceptance.InitDataSourceCheck(byDomainName) | ||
|
||
byAppName = "data.huaweicloud_live_record_callbacks.filter_by_app_name" | ||
dcByAppName = acceptance.InitDataSourceCheck(byAppName) | ||
|
||
allByAppName = "data.huaweicloud_live_record_callbacks.filter_all_by_app_name" | ||
dcAllByAppName = acceptance.InitDataSourceCheck(allByAppName) | ||
) | ||
|
||
resource.ParallelTest(t, resource.TestCase{ | ||
PreCheck: func() { | ||
acceptance.TestAccPreCheck(t) | ||
acceptance.TestAccPreCheckLiveIngestDomainName(t) | ||
}, | ||
ProviderFactories: acceptance.TestAccProviderFactories, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: testDataSourceRecordCallbacks_basic(), | ||
Check: resource.ComposeTestCheckFunc( | ||
dc.CheckResourceExists(), | ||
resource.TestCheckResourceAttrSet(dataSource, "callbacks.0.app_name"), | ||
resource.TestCheckResourceAttrSet(dataSource, "callbacks.0.created_at"), | ||
resource.TestCheckResourceAttrSet(dataSource, "callbacks.0.domain_name"), | ||
resource.TestCheckResourceAttrSet(dataSource, "callbacks.0.id"), | ||
resource.TestCheckResourceAttrSet(dataSource, "callbacks.0.sign_type"), | ||
resource.TestCheckResourceAttrSet(dataSource, "callbacks.0.types.#"), | ||
resource.TestCheckResourceAttrSet(dataSource, "callbacks.0.updated_at"), | ||
resource.TestCheckResourceAttrSet(dataSource, "callbacks.0.url"), | ||
|
||
dcByDomainName.CheckResourceExists(), | ||
resource.TestCheckOutput("domain_name_filter_is_useful", "true"), | ||
|
||
dcByAppName.CheckResourceExists(), | ||
resource.TestCheckOutput("app_name_filter_is_useful", "true"), | ||
|
||
dcAllByAppName.CheckResourceExists(), | ||
resource.TestCheckOutput("all_app_name_filter_is_useful", "true"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
func testDataSourceRecordCallbacks_basic() string { | ||
return fmt.Sprintf(` | ||
%s | ||
data "huaweicloud_live_record_callbacks" "test" { | ||
depends_on = [huaweicloud_live_record_callback.test] | ||
} | ||
# Filter by domain_name | ||
locals { | ||
domain_name = data.huaweicloud_live_record_callbacks.test.callbacks[0].domain_name | ||
} | ||
data "huaweicloud_live_record_callbacks" "filter_by_domain_name" { | ||
depends_on = [huaweicloud_live_record_callback.test] | ||
domain_name = local.domain_name | ||
} | ||
locals { | ||
domain_name_filter_result = [ | ||
for v in data.huaweicloud_live_record_callbacks.filter_by_domain_name.callbacks[*].domain_name : v == local.domain_name | ||
] | ||
} | ||
output "domain_name_filter_is_useful" { | ||
value = alltrue(local.domain_name_filter_result) && length(local.domain_name_filter_result) > 0 | ||
} | ||
# Filter by app_name | ||
locals { | ||
app_name = data.huaweicloud_live_record_callbacks.test.callbacks[0].app_name | ||
} | ||
data "huaweicloud_live_record_callbacks" "filter_by_app_name" { | ||
depends_on = [huaweicloud_live_record_callback.test] | ||
app_name = local.app_name | ||
} | ||
locals { | ||
app_name_filter_result = [ | ||
for v in data.huaweicloud_live_record_callbacks.filter_by_app_name.callbacks[*].app_name : v == local.app_name || v == "*" | ||
] | ||
} | ||
output "app_name_filter_is_useful" { | ||
value = alltrue(local.app_name_filter_result) && length(local.app_name_filter_result) > 0 | ||
} | ||
# Filter all by app_name (*) | ||
data "huaweicloud_live_record_callbacks" "filter_all_by_app_name" { | ||
depends_on = [huaweicloud_live_record_callback.test] | ||
app_name = "*" | ||
} | ||
output "all_app_name_filter_is_useful" { | ||
value = length(data.huaweicloud_live_record_callbacks.filter_all_by_app_name.callbacks) > 0 | ||
} | ||
`, testCallBack_basic()) | ||
} |
169 changes: 169 additions & 0 deletions
169
huaweicloud/services/live/data_source_huaweicloud_live_record_callbacks.go
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,169 @@ | ||
// Generated by PMS #479 | ||
package live | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/hashicorp/go-multierror" | ||
"github.com/hashicorp/go-uuid" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
"github.com/tidwall/gjson" | ||
|
||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/config" | ||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/helper/httphelper" | ||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/helper/schemas" | ||
"github.com/huaweicloud/terraform-provider-huaweicloud/huaweicloud/utils" | ||
) | ||
|
||
func DataSourceLiveRecordCallbacks() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadContext: dataSourceLiveRecordCallbacksRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"region": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Computed: true, | ||
Description: `Specifies the region in which to query the resource. If omitted, the provider-level region will be used.`, | ||
}, | ||
"domain_name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: `Specifies the ingest domain name.`, | ||
}, | ||
"app_name": { | ||
Type: schema.TypeString, | ||
Optional: true, | ||
Description: `Specifies the application name.`, | ||
}, | ||
"callbacks": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Description: `The callback configurations.`, | ||
Elem: &schema.Resource{ | ||
Schema: map[string]*schema.Schema{ | ||
"sign_type": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: `The encryption type.`, | ||
}, | ||
"created_at": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: `The creation time in the format of yyyy-mm-ddThh:mm:ssZ (UTC time).`, | ||
}, | ||
"updated_at": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: `The latest modification time in the format of yyyy-mm-ddThh:mm:ssZ (UTC time).`, | ||
}, | ||
"id": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: `The recording callback ID.`, | ||
}, | ||
"domain_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: `The ingest domain name.`, | ||
}, | ||
"app_name": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: `The application name.`, | ||
}, | ||
"url": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
Description: `The callback URL for sending recording notifications.`, | ||
}, | ||
"types": { | ||
Type: schema.TypeList, | ||
Computed: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
Description: `The types of recording notifications.`, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
type RecordCallbacksDSWrapper struct { | ||
*schemas.ResourceDataWrapper | ||
Config *config.Config | ||
} | ||
|
||
func newRecordCallbacksDSWrapper(d *schema.ResourceData, meta interface{}) *RecordCallbacksDSWrapper { | ||
return &RecordCallbacksDSWrapper{ | ||
ResourceDataWrapper: schemas.NewSchemaWrapper(d), | ||
Config: meta.(*config.Config), | ||
} | ||
} | ||
|
||
func dataSourceLiveRecordCallbacksRead(_ context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
wrapper := newRecordCallbacksDSWrapper(d, meta) | ||
lisRecCalConRst, err := wrapper.ListRecordCallbackConfigs() | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
id, err := uuid.GenerateUUID() | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
d.SetId(id) | ||
|
||
err = wrapper.listRecordCallbackConfigsToSchema(lisRecCalConRst) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
return nil | ||
} | ||
|
||
// @API LIVE GET /v1/{project_id}/record/callbacks | ||
func (w *RecordCallbacksDSWrapper) ListRecordCallbackConfigs() (*gjson.Result, error) { | ||
client, err := w.NewClient(w.Config, "live") | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
uri := "/v1/{project_id}/record/callbacks" | ||
params := map[string]any{ | ||
"publish_domain": w.Get("domain_name"), | ||
"app": w.Get("app_name"), | ||
} | ||
params = utils.RemoveNil(params) | ||
return httphelper.New(client). | ||
Method("GET"). | ||
URI(uri). | ||
Query(params). | ||
OffsetPager("callback_config", "offset", "limit", 0). | ||
Request(). | ||
Result() | ||
} | ||
|
||
func (w *RecordCallbacksDSWrapper) listRecordCallbackConfigsToSchema(body *gjson.Result) error { | ||
d := w.ResourceData | ||
mErr := multierror.Append(nil, | ||
d.Set("region", w.Config.GetRegion(w.ResourceData)), | ||
d.Set("callbacks", schemas.SliceToList(body.Get("callback_config"), | ||
func(callbacks gjson.Result) any { | ||
return map[string]any{ | ||
"sign_type": callbacks.Get("sign_type").Value(), | ||
"created_at": callbacks.Get("create_time").Value(), | ||
"updated_at": callbacks.Get("update_time").Value(), | ||
"id": callbacks.Get("id").Value(), | ||
"domain_name": callbacks.Get("publish_domain").Value(), | ||
"app_name": callbacks.Get("app").Value(), | ||
"url": callbacks.Get("notify_callback_url").Value(), | ||
"types": schemas.SliceToStrList(callbacks.Get("notify_event_subscription")), | ||
} | ||
}, | ||
)), | ||
) | ||
return mErr.ErrorOrNil() | ||
} |