This commit is contained in:
2024-05-31 14:05:21 +03:00
parent 84b7a80e1b
commit db1760cb72
815 changed files with 58194 additions and 11049 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>
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 user
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 dataSourceUserRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
user, err := utilityUserCheckPresence(ctx, d, m)
if err != nil {
d.SetId("") // ensure ID is empty in this case
return diag.FromErr(err)
}
flattenUserDataSource(d, user)
d.SetId(d.Get("user_id").(string))
return nil
}
func DataSourceUser() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceUserRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceUserSchemaMake(),
}
}

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>
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 user
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 dataSourceUserGetAuditRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
audits, err := utilityUserGetAuditCheckPresence(ctx, d, m)
if err != nil {
d.SetId("") // ensure ID is empty in this case
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
d.Set("items", flattenUserGetAudits(audits))
d.Set("entry_count", audits.EntryCount)
return nil
}
func DataSourceUserGetAudit() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceUserGetAuditRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceUserGetAuditSchemaMake(),
}
}

View File

@@ -0,0 +1,73 @@
/*
Copyright (c) 2019-2023 Digital Energy Cloud Solutions LLC. All Rights Reserved.
Authors:
Petr Krutov, <petr.krutov@digitalenergy.online>
Stanislav Solovev, <spsolovev@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 user
import (
"context"
"github.com/google/uuid"
log "github.com/sirupsen/logrus"
"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 dataSourceUserListRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
users, err := utilityUserListCheckPresence(ctx, d, m)
if err != nil {
d.SetId("") // ensure ID is empty in this case
return diag.FromErr(err)
}
id := uuid.New()
d.SetId(id.String())
err = d.Set("items", flattenUserList(users))
log.Debug("err:", err)
d.Set("entry_count", users.EntryCount)
return nil
}
func DataSourceUserList() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
ReadContext: dataSourceUserListRead,
Timeouts: &schema.ResourceTimeout{
Read: &constants.Timeout30s,
Default: &constants.Timeout60s,
},
Schema: dataSourceUserListSchemaMake(),
}
}

View File

@@ -0,0 +1,184 @@
/*
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 user
import (
"strconv"
log "github.com/sirupsen/logrus"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/user"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/flattens"
)
func flattenUserDataSource(d *schema.ResourceData, details *user.ItemUser) {
log.Debugf("flattenUser: decoded User ID %s",
details.ID)
d.Set("user_id", details.ID)
d.Set("ckey", details.CKey)
d.Set("meta", flattens.FlattenMeta(details.Meta))
d.Set("api_access", details.APIAccess)
d.Set("active", details.Active)
d.Set("authkey", details.AuthKey)
d.Set("auth_keys", flattenItemUser(details.AuthKeys))
d.Set("data", details.Data)
d.Set("description", details.Description)
d.Set("domain", details.Domain)
d.Set("emails", details.Emails)
d.Set("gid", details.GID)
d.Set("groups", details.Groups)
d.Set("guid", details.GUID)
d.Set("last_check", details.LastCheck)
d.Set("mobile", flattenItemUser(details.Mobile))
d.Set("password", details.Password)
d.Set("protected", details.Protected)
d.Set("roles", flattenItemUser(details.Roles))
d.Set("service_account", details.ServiceAccount)
d.Set("xmpp", flattenItemUser(details.XMPP))
}
func flattenUserResource(d *schema.ResourceData, details *user.ItemUser) {
log.Debugf("flattenUser: decoded User ID %s",
details.ID)
d.Set("username", details.ID)
d.Set("ckey", details.CKey)
d.Set("meta", flattens.FlattenMeta(details.Meta))
d.Set("apiaccess", flattenAPIAcess(details.APIAccess))
d.Set("active", details.Active)
d.Set("authkey", details.AuthKey)
d.Set("auth_keys", flattenItemUser(details.AuthKeys))
d.Set("data", details.Data)
d.Set("description", details.Description)
d.Set("domain", details.Domain)
d.Set("emailaddress", details.Emails)
d.Set("gid", details.GID)
d.Set("groups", details.Groups)
d.Set("guid", details.GUID)
d.Set("last_check", details.LastCheck)
d.Set("mobile", flattenItemUser(details.Mobile))
d.Set("protected", details.Protected)
d.Set("roles", flattenItemUser(details.Roles))
d.Set("service_account", details.ServiceAccount)
d.Set("xmpp", flattenItemUser(details.XMPP))
}
func flattenItemUser(m []interface{}) []string {
output := []string{}
for _, item := range m {
switch d := item.(type) {
case string:
output = append(output, d)
case int:
output = append(output, strconv.Itoa(d))
case int64:
output = append(output, strconv.FormatInt(d, 10))
case float64:
output = append(output, strconv.FormatInt(int64(d), 10))
default:
output = append(output, "")
}
}
return output
}
func flattenUserGetAudits(audits *user.ListAudits) []map[string]interface{} {
log.Debug("flattenUserGetAudits")
res := make([]map[string]interface{}, 0, len(audits.Data))
for _, item := range audits.Data {
temp := map[string]interface{}{
"call": item.Call,
"response_time": item.ResponseTime,
"status_code": item.StatusCode,
"time": item.Time,
}
res = append(res, temp)
}
return res
}
func flattenUserList(users *user.ListUsers) []map[string]interface{} {
log.Debug("flattenUserList")
res := make([]map[string]interface{}, 0, len(users.Data))
for _, item := range users.Data {
temp := map[string]interface{}{
"ckey": item.CKey,
"meta": flattens.FlattenMeta(item.Meta),
"api_access": item.APIAccess,
"active": item.Active,
"authkey": item.AuthKey,
"authkeys": flattenItemUser(item.AuthKeys),
"data": item.Data,
"description": item.Description,
"domain": item.Domain,
"emails": item.Emails,
"gid": item.GID,
"groups": item.Groups,
"guid": item.GUID,
"user_id": item.ID,
"last_check": item.LastCheck,
"mobile": flattenItemUser(item.Mobile),
"password": item.Password,
"protected": item.Protected,
"roles": flattenItemUser(item.Roles),
"service_account": item.ServiceAccount,
"xmpp": flattenItemUser(item.XMPP),
}
res = append(res, temp)
}
return res
}
func flattenAPIAcess(in map[string]string) []int {
res := make([]int, 0, len(in))
for i := range in {
num, err := strconv.Atoi(i)
if err != nil {
log.Errorf("flattenAPIAcess: unable to convert %s to digit %v", i, err)
return nil
}
res = append(res, num)
}
return res
}

View File

@@ -0,0 +1,149 @@
package user
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/user"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/constants"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func resourceUserCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceUserCreate: called with username %s, emailaddress %v", d.Get("username").(string), d.Get("emailaddress").([]interface{}))
c := m.(*controller.ControllerCfg)
username := d.Get("username").(string)
emails := d.Get("emailaddress").([]interface{})
emailAddress := make([]string, 0, len(emails))
for _, v := range emails {
emailAddress = append(emailAddress, v.(string))
}
createReq := user.CreateRequest{
Username: username,
EmailAddress: emailAddress,
}
if passwd, ok := d.GetOk("password"); ok {
createReq.Password = passwd.(string)
}
if aa, ok := d.GetOk("apiaccess"); ok {
apiaccess := aa.(*schema.Set)
for _, v := range apiaccess.List() {
createReq.APIAccess = append(createReq.APIAccess, uint64(v.(int)))
}
}
if groups, ok := d.GetOk("groups"); ok {
for _, v := range groups.([]interface{}) {
createReq.Groups = append(createReq.Groups, v.(string))
}
}
_, err := c.CloudBroker().User().Create(ctx, createReq)
if err != nil {
return diag.FromErr(err)
}
d.SetId(username)
return resourceUserRead(ctx, d, m)
}
func resourceUserRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceUserRead: called with username %s", d.Get("username").(string))
user, err := utilityUserCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
flattenUserResource(d, user)
return nil
}
func resourceUserUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceUserUpdate: called with username %s", d.Get("username").(string))
if d.HasChange("apiaccess") {
err := utilityUserAPIAccessGroupsConfigure(ctx, d, m)
if err != nil {
return diag.FromErr(err)
}
}
return resourceUserRead(ctx, d, m)
}
func resourceUserDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
log.Debugf("resourceUserDelete: called with username %s", d.Get("username").(string))
usr, err := utilityUserCheckPresence(ctx, d, m)
if err != nil {
d.SetId("")
return diag.FromErr(err)
}
c := m.(*controller.ControllerCfg)
req := user.DeleteRequest{
Username: usr.ID,
}
_, err = c.CloudBroker().User().Delete(ctx, req)
if err != nil {
return diag.FromErr(err)
}
d.SetId("")
return nil
}
func ResourceUser() *schema.Resource {
return &schema.Resource{
SchemaVersion: 1,
CreateContext: resourceUserCreate,
ReadContext: resourceUserRead,
UpdateContext: resourceUserUpdate,
DeleteContext: resourceUserDelete,
Importer: &schema.ResourceImporter{
StateContext: schema.ImportStatePassthroughContext,
},
Timeouts: &schema.ResourceTimeout{
Create: &constants.Timeout600s,
Read: &constants.Timeout600s,
Update: &constants.Timeout600s,
Delete: &constants.Timeout600s,
Default: &constants.Timeout600s,
},
Schema: resourceUserSchemaMake(),
}
}

View File

@@ -0,0 +1,525 @@
package user
import (
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
)
func dataSourceUserSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"user_id": {
Type: schema.TypeString,
Required: true,
Description: "user_id",
},
"ckey": {
Type: schema.TypeString,
Computed: true,
Description: "ckey",
},
"meta": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "meta",
},
"active": {
Type: schema.TypeBool,
Computed: true,
Description: "active",
},
"api_access": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "api_access",
},
"authkey": {
Type: schema.TypeString,
Computed: true,
Description: "authkey",
},
"authkeys": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "authkeys",
},
"data": {
Type: schema.TypeString,
Computed: true,
Description: "data",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "description",
},
"domain": {
Type: schema.TypeString,
Computed: true,
Description: "domain",
},
"emails": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "emails",
},
"gid": {
Type: schema.TypeInt,
Computed: true,
Description: "gid",
},
"groups": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "groups",
},
"guid": {
Type: schema.TypeString,
Computed: true,
Description: "guid",
},
"last_check": {
Type: schema.TypeInt,
Computed: true,
Description: "last_check",
},
"mobile": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "mobile",
},
"password": {
Type: schema.TypeString,
Computed: true,
Description: "password",
},
"protected": {
Type: schema.TypeBool,
Computed: true,
Description: "protected",
},
"roles": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "roles",
},
"service_account": {
Type: schema.TypeBool,
Computed: true,
Description: "service_account",
},
"xmpp": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "xmpp",
},
}
}
func dataSourceUserGetAuditSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"username": {
Type: schema.TypeString,
Optional: true,
Description: "name of user (get audits for current user if set to empty)",
},
"call": {
Type: schema.TypeString,
Optional: true,
Description: "find by api call",
},
"status_code": {
Type: schema.TypeInt,
Optional: true,
Description: "find by status code",
},
"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)",
},
"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,
},
"response_time": {
Type: schema.TypeFloat,
Computed: true,
},
"status_code": {
Type: schema.TypeInt,
Computed: true,
},
"time": {
Type: schema.TypeFloat,
Computed: true,
},
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
Description: "entry_count",
},
}
}
func dataSourceUserListSchemaMake() map[string]*schema.Schema {
return map[string]*schema.Schema{
"by_id": {
Type: schema.TypeString,
Optional: true,
Description: "find by id",
},
"active": {
Type: schema.TypeBool,
Optional: true,
Description: "find by active. True or False",
},
"service_account": {
Type: schema.TypeBool,
Optional: true,
Description: "find by service account. True or False",
},
"sort_by": {
Type: schema.TypeString,
Optional: true,
Description: "sort by one of supported fields, format +|-(field)",
},
"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{
"ckey": {
Type: schema.TypeString,
Computed: true,
Description: "ckey",
},
"meta": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "meta",
},
"active": {
Type: schema.TypeBool,
Computed: true,
Description: "active",
},
"apiaccess": {
Type: schema.TypeMap,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "apiaccess",
},
"authkey": {
Type: schema.TypeString,
Computed: true,
Description: "authkey",
},
"authkeys": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "authkeys",
},
"data": {
Type: schema.TypeString,
Computed: true,
Description: "data",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "description",
},
"domain": {
Type: schema.TypeString,
Computed: true,
Description: "domain",
},
"emails": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "emails",
},
"gid": {
Type: schema.TypeInt,
Computed: true,
Description: "gid",
},
"groups": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "groups",
},
"guid": {
Type: schema.TypeString,
Computed: true,
Description: "guid",
},
"user_id": {
Type: schema.TypeString,
Computed: true,
Description: "user id",
},
"last_check": {
Type: schema.TypeInt,
Computed: true,
Description: "last_check",
},
"mobile": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "mobile",
},
"password": {
Type: schema.TypeString,
Computed: true,
Description: "password",
},
"protected": {
Type: schema.TypeBool,
Computed: true,
Description: "protected",
},
"roles": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "roles",
},
"service_account": {
Type: schema.TypeBool,
Computed: true,
Description: "service_account",
},
"xmpp": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "xmpp",
},
},
},
},
"entry_count": {
Type: schema.TypeInt,
Computed: true,
Description: "entry_count",
},
}
}
func resourceUserSchemaMake() map[string]*schema.Schema {
log.Debugf("resourceUserSchemaMake: invoked")
return map[string]*schema.Schema{
"username": {
Type: schema.TypeString,
Required: true,
Description: "ID of user",
},
"emailaddress": {
Type: schema.TypeList,
Required: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "email addresses of the user",
},
"password": {
Type: schema.TypeString,
Optional: true,
Description: "password of user",
},
"groups": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "list of groups this user belongs to",
},
"ckey": {
Type: schema.TypeString,
Computed: true,
Description: "ckey",
},
"meta": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "meta",
},
"active": {
Type: schema.TypeBool,
Computed: true,
Description: "active",
},
"apiaccess": {
Type: schema.TypeSet,
Optional: true,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeInt,
},
Description: "list of apiaccess groups this user belongs to",
},
"authkey": {
Type: schema.TypeString,
Computed: true,
Description: "authkey",
},
"auth_keys": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "authkeys",
},
"data": {
Type: schema.TypeString,
Computed: true,
Description: "data",
},
"description": {
Type: schema.TypeString,
Computed: true,
Description: "description",
},
"domain": {
Type: schema.TypeString,
Computed: true,
Description: "domain",
},
"gid": {
Type: schema.TypeInt,
Computed: true,
Description: "gid",
},
"guid": {
Type: schema.TypeString,
Computed: true,
Description: "guid",
},
"last_check": {
Type: schema.TypeInt,
Computed: true,
Description: "last_check",
},
"mobile": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "mobile",
},
"protected": {
Type: schema.TypeBool,
Computed: true,
Description: "protected",
},
"roles": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "roles",
},
"service_account": {
Type: schema.TypeBool,
Computed: true,
Description: "service_account",
},
"xmpp": {
Type: schema.TypeList,
Computed: true,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Description: "xmpp",
},
}
}

View File

@@ -0,0 +1,108 @@
/*
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 user
import (
"context"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/user"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
log "github.com/sirupsen/logrus"
)
func utilityUserCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*user.ItemUser, error) {
c := m.(*controller.ControllerCfg)
req := user.GetRequest{}
if d.Id() != "" {
req.UserID = d.Id()
} else {
req.UserID = d.Get("user_id").(string)
}
userInfo, err := c.CloudBroker().User().Get(ctx, req)
if err != nil {
return nil, err
}
return userInfo, nil
}
func utilityUserAPIAccessGroupsConfigure(ctx context.Context, d *schema.ResourceData, m interface{}) error {
c := m.(*controller.ControllerCfg)
old_set, new_set := d.GetChange("apiaccess")
leave_set := old_set.(*schema.Set).Difference(new_set.(*schema.Set))
log.Debugf("utilityUserAPIAccessGroupsConfigure: leave set has %d items for Username %s", leave_set.Len(), d.Id())
if leave_set.Len() > 0 {
for _, v := range leave_set.List() {
leaveReq := user.APIAccessLeaveRequest{
UserID: d.Id(),
APIAccessID: uint64(v.(int)),
}
_, err := c.CloudBroker().User().APIAccessLeave(ctx, leaveReq)
if err != nil {
return err
}
}
}
join_set := new_set.(*schema.Set).Difference(old_set.(*schema.Set))
log.Debugf("utilityUserAPIAccessGroupsConfigure: join set has %d items for Username %s", join_set.Len(), d.Id())
if join_set.Len() > 0 {
for _, v := range join_set.List() {
joinReq := user.APIAccessJoinRequest{
UserID: d.Id(),
APIAccessID: uint64(v.(int)),
}
_, err := c.CloudBroker().User().APIAccessJoin(ctx, joinReq)
if err != nil {
return err
}
}
}
return nil
}

View File

@@ -0,0 +1,77 @@
/*
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 user
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/user"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityUserGetAuditCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*user.ListAudits, error) {
c := m.(*controller.ControllerCfg)
req := user.GetAuditRequest{}
if username, ok := d.GetOk("username"); ok {
req.Username = username.(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 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 Page, ok := d.GetOk("page"); ok {
req.Page = uint64(Page.(int))
}
if Size, ok := d.GetOk("size"); ok {
req.Size = uint64(Size.(int))
}
audits, err := c.CloudBroker().User().GetAudit(ctx, req)
if err != nil {
return nil, err
}
return &audits, nil
}

View File

@@ -0,0 +1,77 @@
/*
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 user
import (
"context"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"repository.basistech.ru/BASIS/decort-golang-sdk/pkg/cloudbroker/user"
"repository.basistech.ru/BASIS/terraform-provider-decort/internal/controller"
)
func utilityUserListCheckPresence(ctx context.Context, d *schema.ResourceData, m interface{}) (*user.ListUsers, error) {
c := m.(*controller.ControllerCfg)
req := user.ListRequest{}
if byId, ok := d.GetOk("by_id"); ok {
req.ByID = byId.(string)
}
if active, ok := d.GetOk("active"); ok {
req.Active = active.(bool)
}
if serviceAccount, ok := d.GetOk("service_account"); ok {
req.ServiceAccount = serviceAccount.(bool)
}
if sortBy, ok := d.GetOk("sort_by"); ok {
req.SortBy = sortBy.(string)
}
if Page, ok := d.GetOk("page"); ok {
req.Page = uint64(Page.(int))
}
if Size, ok := d.GetOk("size"); ok {
req.Size = uint64(Size.(int))
}
usersList, err := c.CloudBroker().User().List(ctx, req)
if err != nil {
return nil, err
}
return usersList, nil
}