refactoring; dropped some unused code; configured linters
This commit is contained in:
@@ -11,7 +11,7 @@ linters:
|
|||||||
- gosec
|
- gosec
|
||||||
- ifshort
|
- ifshort
|
||||||
- makezero
|
- makezero
|
||||||
- nestif
|
#- nestif - disabled till better times
|
||||||
- nilerr
|
- nilerr
|
||||||
- prealloc
|
- prealloc
|
||||||
- unconvert
|
- unconvert
|
||||||
|
|||||||
@@ -428,7 +428,7 @@ func isChangedUser(els []interface{}, el interface{}) bool {
|
|||||||
elOldConv := elOld.(map[string]interface{})
|
elOldConv := elOld.(map[string]interface{})
|
||||||
elConv := el.(map[string]interface{})
|
elConv := el.(map[string]interface{})
|
||||||
if elOldConv["user_id"].(string) == elConv["user_id"].(string) &&
|
if elOldConv["user_id"].(string) == elConv["user_id"].(string) &&
|
||||||
(strings.ToUpper(elOldConv["access_type"].(string)) != strings.ToUpper(elConv["access_type"].(string)) ||
|
(!strings.EqualFold(elOldConv["access_type"].(string), elConv["access_type"].(string)) ||
|
||||||
elOldConv["recursive_delete"].(bool) != elConv["recursive_delete"].(bool)) {
|
elOldConv["recursive_delete"].(bool) != elConv["recursive_delete"].(bool)) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,104 +0,0 @@
|
|||||||
/*
|
|
||||||
Copyright (c) 2019-2021 Digital Energy Cloud Solutions LLC. All Rights Reserved.
|
|
||||||
Author: Sergey Shubin, <sergey.shubin@digitalenergy.online>, <svs1370@gmail.com>
|
|
||||||
|
|
||||||
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.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package decort
|
|
||||||
|
|
||||||
import (
|
|
||||||
"fmt"
|
|
||||||
|
|
||||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
|
||||||
// "github.com/hashicorp/terraform-plugin-sdk/helper/validation"
|
|
||||||
)
|
|
||||||
|
|
||||||
/*
|
|
||||||
func makeSshKeysConfig(arg_list []interface{}) (sshkeys []SshKeyConfig, count int) {
|
|
||||||
count = len(arg_list)
|
|
||||||
if count < 1 {
|
|
||||||
return nil, 0
|
|
||||||
}
|
|
||||||
|
|
||||||
sshkeys = make([]SshKeyConfig, count)
|
|
||||||
var subres_data map[string]interface{}
|
|
||||||
for index, value := range arg_list {
|
|
||||||
subres_data = value.(map[string]interface{})
|
|
||||||
sshkeys[index].User = subres_data["user"].(string)
|
|
||||||
sshkeys[index].SshKey = subres_data["public_key"].(string)
|
|
||||||
sshkeys[index].UserShell = subres_data["shell"].(string)
|
|
||||||
}
|
|
||||||
|
|
||||||
return sshkeys, count
|
|
||||||
}
|
|
||||||
*/
|
|
||||||
|
|
||||||
func makeSshKeysArgString(arg_list []interface{}) string {
|
|
||||||
// This function expects arg_list = data.Get("ssh_keys"), where "data" is a populated schema for Compute
|
|
||||||
// Resource (see func resourceCompute() definition) or Compute Data Source (see func dataSourceCompute())
|
|
||||||
|
|
||||||
// Prepare a string with username and public ssh key value in a format recognized by cloud-init utility.
|
|
||||||
// It is designed to be passed as "userdata" argument of virtual machine create API call.
|
|
||||||
// The following format is expected:
|
|
||||||
// '{"users": [{"ssh-authorized-keys": ["SSH_PUBCIC_KEY_VALUE"], "shell": "SHELL_VALUE", "name": "USERNAME_VALUE"}, {...}, ]}'
|
|
||||||
|
|
||||||
/*
|
|
||||||
`%s\n
|
|
||||||
- name: %s\n
|
|
||||||
ssh-authorized-keys:
|
|
||||||
- %s\n
|
|
||||||
shell: /bin/bash`
|
|
||||||
*/
|
|
||||||
|
|
||||||
if len(arg_list) < 1 {
|
|
||||||
return ""
|
|
||||||
}
|
|
||||||
|
|
||||||
out := `{"users": [`
|
|
||||||
const UserdataTemplate = `%s{"ssh-authorized-keys": ["%s"], "shell": "%s", "name": "%s"}, `
|
|
||||||
const out_suffix = `]}`
|
|
||||||
|
|
||||||
for _, value := range arg_list {
|
|
||||||
subres_data := value.(map[string]interface{})
|
|
||||||
|
|
||||||
out = fmt.Sprintf(UserdataTemplate, out, subres_data["public_key"].(string), subres_data["shell"].(string), subres_data["user"].(string))
|
|
||||||
}
|
|
||||||
out = fmt.Sprintf("%s %s", out, out_suffix)
|
|
||||||
return out
|
|
||||||
}
|
|
||||||
|
|
||||||
func sshSubresourceSchemaMake() map[string]*schema.Schema {
|
|
||||||
rets := map[string]*schema.Schema{
|
|
||||||
"user": {
|
|
||||||
Type: schema.TypeString,
|
|
||||||
Required: true,
|
|
||||||
Description: "Name of the guest OS user of a new compute, for which the following SSH key will be authorized.",
|
|
||||||
},
|
|
||||||
|
|
||||||
"public_key": {
|
|
||||||
Type: schema.TypeString,
|
|
||||||
Required: true,
|
|
||||||
Description: "Public SSH key to authorize to the specified guest OS user on the compute being created.",
|
|
||||||
},
|
|
||||||
|
|
||||||
"shell": {
|
|
||||||
Type: schema.TypeString,
|
|
||||||
Optional: true,
|
|
||||||
Default: "/bin/bash",
|
|
||||||
Description: "Guest user shell. This parameter is optional, default is /bin/bash.",
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
return rets
|
|
||||||
}
|
|
||||||
@@ -32,7 +32,7 @@ import (
|
|||||||
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
|
||||||
)
|
)
|
||||||
|
|
||||||
func utilityExtnetDefaultCheckPresence(d *schema.ResourceData, m interface{}) (string, error) {
|
func utilityExtnetDefaultCheckPresence(_ *schema.ResourceData, m interface{}) (string, error) {
|
||||||
controller := m.(*ControllerCfg)
|
controller := m.(*ControllerCfg)
|
||||||
urlValues := &url.Values{}
|
urlValues := &url.Values{}
|
||||||
|
|
||||||
|
|||||||
@@ -129,11 +129,3 @@ func utilityResgroupCheckPresence(d *schema.ResourceData, m interface{}) (string
|
|||||||
|
|
||||||
return "", fmt.Errorf("Cannot find RG name %s owned by account ID %d", rgName, d.Get("account_id").(int))
|
return "", fmt.Errorf("Cannot find RG name %s owned by account ID %d", rgName, d.Get("account_id").(int))
|
||||||
}
|
}
|
||||||
|
|
||||||
func utilityResgroupGetDefaultGridID() (interface{}, error) {
|
|
||||||
if DefaultGridID > 0 {
|
|
||||||
return fmt.Sprintf("%d", DefaultGridID), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return "", fmt.Errorf("utilityResgroupGetDefaultGridID: invalid default Grid ID %d", DefaultGridID)
|
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user