This commit is contained in:
2023-12-18 18:55:52 +03:00
parent e2ee45ee14
commit 20050bc169
213 changed files with 37547 additions and 2873 deletions

View File

@@ -0,0 +1,68 @@
/*
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Sergey Kisil, <svkisil@digitalenergy.online>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package audit
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func dataSourceAuditRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
auditRec, err := utilityAuditCheckPresence(ctx, d, m)
if err != nil {
d.SetId("") // ensure ID is empty in this case
return diag.FromErr(err)
}
flattenAudit(d, auditRec)
d.SetId(d.Get("audit_guid").(string))
return nil
}
func DataSourceAudit() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceAuditRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceAuditSchemaMake(),
}
}

View File

@@ -0,0 +1,71 @@
/*
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Sergey Kisil, <svkisil@digitalenergy.online>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package audit
import (
"context"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func dataSourceLinkedJobsRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
linkedJobs, err := utilityLinkedJobsCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenLinkedJobs(linkedJobs))
return nil
}
func DataSourceAuditLinkedJobs() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceLinkedJobsRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceLinkedJobsSchemaMake(),
}
}

View File

@@ -0,0 +1,72 @@
/*
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Sergey Kisil, <svkisil@digitalenergy.online>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package audit
import (
"context"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
)
func dataSourceAuditListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
auditList, err := utilityAuditListCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenAuditList(auditList))
d.Set("entry_count", auditList.EntryCount)
return nil
}
func DataSourceAuditList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceAuditListRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceAuditListSchemaMake(),
}
}

View File

@@ -0,0 +1,91 @@
/*
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Sergey Kisil, <svkisil@digitalenergy.online>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package audit
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/audit"
)
func flattenAudit(d *schema.ResourceData, au *audit.RecordAudit) {
log.Debugf("flattenAudit: decoded audit guid %s", d.Get("audit_guid").(string))
d.Set("apitask", au.Apitask)
d.Set("args", au.Arguments)
d.Set("call", au.Call)
d.Set("guid", au.GUID)
d.Set("kwargs", au.Kwargs)
d.Set("remote_addr", au.RemoteAddr)
d.Set("responsetime", au.ResponseTime)
d.Set("result", au.Result)
d.Set("status_code", au.StatusCode)
d.Set("tags", au.Tags)
d.Set("timestamp", au.Timestamp)
d.Set("timestamp_end", au.TimestampEnd)
d.Set("user", au.User)
}
func flattenAuditList(au *audit.ListAudits) []map[string]interface{} {
res := make([]map[string]interface{}, 0, len(au.Data))
for _, item := range au.Data {
temp := map[string]interface{}{
"call": item.Call,
"guid": item.GUID,
"responsetime": item.ResponseTime,
"status_code": item.StatusCode,
"timestamp": item.Timestamp,
"user": item.User,
}
res = append(res, temp)
}
return res
}
func flattenLinkedJobs(ljl *audit.ListLinkedJobs) []map[string]interface{} {
res := make([]map[string]interface{}, 0)
linkedJobs := *ljl
for _, item := range linkedJobs {
temp := map[string]interface{}{
"cmd": item.CMD,
"nid": item.NID,
"state": item.State,
"time_create": item.TimeCreate,
"time_start": item.TimeStart,
"time_stop": item.TimeStop,
"timeout": item.Timeout,
}
res = append(res, temp)
}
return res
}

View File

@@ -0,0 +1,198 @@
package audit
import "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
func dataSourceAuditSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"audit_guid": {
Type: schema.TypeString,
Required: true,
Description: "audit guid",
},
"apitask": {
Type: schema.TypeString,
Computed: true,
},
"args": {
Type: schema.TypeString,
Computed: true,
},
"call": {
Type: schema.TypeString,
Computed: true,
},
"guid": {
Type: schema.TypeString,
Computed: true,
},
"kwargs": {
Type: schema.TypeString,
Computed: true,
},
"remote_addr": {
Type: schema.TypeString,
Computed: true,
},
"responsetime": {
Type: schema.TypeFloat,
Computed: true,
},
"result": {
Type: schema.TypeString,
Computed: true,
},
"status_code": {
Type: schema.TypeInt,
Computed: true,
},
"tags": {
Type: schema.TypeString,
Computed: true,
},
"timestamp": {
Type: schema.TypeFloat,
Computed: true,
},
"timestamp_end": {
Type: schema.TypeFloat,
Computed: true,
},
"user": {
Type: schema.TypeString,
Computed: true,
},
}
}
func dataSourceAuditListSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"timestamp_at": {
Type: schema.TypeInt,
Optional: true,
Description: "find all audits after point in time (unixtime)",
},
"timestamp_to": {
Type: schema.TypeInt,
Optional: true,
Description: "find all audits before point in time (unixtime)",
},
"user": {
Type: schema.TypeString,
Optional: true,
Description: "find by user (Mongo RegExp supported)",
},
"call": {
Type: schema.TypeString,
Optional: true,
Description: "find by api endpoint (Mongo RegExp supported)",
},
"status_code": {
Type: schema.TypeInt,
Optional: true,
Description: "find by HTTP status code",
},
"page": {
Type: schema.TypeInt,
Optional: true,
Description: "page number",
},
"size": {
Type: schema.TypeInt,
Optional: true,
Description: "page size",
},
"items": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"call": {
Type: schema.TypeString,
Computed: true,
},
"guid": {
Type: schema.TypeString,
Computed: true,
},
"responsetime": {
Type: schema.TypeFloat,
Computed: true,
},
"status_code": {
Type: schema.TypeInt,
Computed: true,
},
"timestamp": {
Type: schema.TypeFloat,
Computed: true,
},
"user": {
Type: schema.TypeString,
Computed: true,
},
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
Description: "entry count",
},
}
}
func dataSourceLinkedJobsSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"audit_guid": {
Type: schema.TypeString,
Required: true,
Description: "audit guid",
},
"items": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"cmd": {
Type: schema.TypeString,
Computed: true,
Description: "cmd",
},
"nid": {
Type: schema.TypeInt,
Computed: true,
Description: "nid",
},
"state": {
Type: schema.TypeString,
Computed: true,
Description: "state",
},
"time_create": {
Type: schema.TypeInt,
Computed: true,
Description: "time create",
},
"time_start": {
Type: schema.TypeInt,
Computed: true,
Description: "time start",
},
"time_stop": {
Type: schema.TypeInt,
Computed: true,
Description: "time stop",
},
"timeout": {
Type: schema.TypeInt,
Computed: true,
Description: "timeout",
},
},
},
},
}
}

View File

@@ -0,0 +1,62 @@
/*
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Sergey Kisil, <svkisil@digitalenergy.online>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package audit
import (
"context"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/audit"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityAuditCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*audit.RecordAudit, error) {
c := m.(*controller.ControllerCfg)
req := audit.GetRequest{}
if d.Id() != "" {
req.AuditGuid = d.Id()
} else {
req.AuditGuid = d.Get("audit_guid").(string)
}
log.Debugf("utilityStackCheckPresence: load stack")
auditInfo, err := c.CloudBroker().Audit().Get(ctx, req)
if err != nil {
return nil, err
}
return auditInfo, nil
}

View File

@@ -0,0 +1,56 @@
/*
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Sergey Kisil, <svkisil@digitalenergy.online>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package audit
import (
"context"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/audit"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityLinkedJobsCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*audit.ListLinkedJobs, error) {
c := m.(*controller.ControllerCfg)
req := audit.LinkedJobsRequest{AuditGuid: d.Get("audit_guid").(string)}
log.Debugf("utilityLinkedJobsCheckPresence: load linked jobs")
linkedJobsList, err := c.CloudBroker().Audit().LinkedJobs(ctx, req)
if err != nil {
return nil, err
}
return linkedJobsList, nil
}

View File

@@ -0,0 +1,78 @@
/*
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@digitalenergy.online>
Sergey Kisil, <svkisil@digitalenergy.online>
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
/*
Terraform DECORT provider - manage resources provided by DECORT (Digital Energy Cloud
Orchestration Technology) with Terraform by Hashicorp.
Source code: https://repository.basistech.ru/BASIS/terraform-provider-decort
Please see README.md to learn where to place source code so that it
builds seamlessly.
Documentation: https://repository.basistech.ru/BASIS/terraform-provider-decort/wiki
*/
package audit
import (
"context"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/audit"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
func utilityAuditListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*audit.ListAudits, error) {
c := m.(*controller.ControllerCfg)
req := audit.ListRequest{}
if timestampAt, ok := d.GetOk("timestamp_at"); ok {
req.TimestampAt = uint64(timestampAt.(int))
}
if timestampTo, ok := d.GetOk("timestamp_to"); ok {
req.TimestampTo = uint64(timestampTo.(int))
}
if user, ok := d.GetOk("user"); ok {
req.User = user.(string)
}
if call, ok := d.GetOk("call"); ok {
req.Call = call.(string)
}
if statusCode, ok := d.GetOk("status_code"); ok {
req.StatusCode = uint64(statusCode.(int))
}
if Page, ok := d.GetOk("page"); ok {
req.Page = uint64(Page.(int))
}
if Size, ok := d.GetOk("size"); ok {
req.Size = uint64(Size.(int))
}
log.Debugf("utilityAuditListCheckPresence: load audit list")
auditList, err := c.CloudBroker().Audit().List(ctx, req)
if err != nil {
return nil, err
}
return auditList, nil
}