From 545eac90dfaf654c079d2a4f8dfaf9923424ad92 Mon Sep 17 00:00:00 2001 From: kjubybot Date: Wed, 8 Jun 2022 15:55:16 +0300 Subject: [PATCH] refactoring; dropped some unused code; configured linters --- .golangci.yml | 2 +- decort/resource_account.go | 2 +- decort/ssh_subresource.go | 104 ------------------------------- decort/utility_extnet_default.go | 2 +- decort/utility_rg.go | 8 --- 5 files changed, 3 insertions(+), 115 deletions(-) delete mode 100644 decort/ssh_subresource.go diff --git a/.golangci.yml b/.golangci.yml index 49ad9be..808f9e1 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -11,7 +11,7 @@ linters: - gosec - ifshort - makezero - - nestif + #- nestif - disabled till better times - nilerr - prealloc - unconvert diff --git a/decort/resource_account.go b/decort/resource_account.go index e266560..66fc97c 100644 --- a/decort/resource_account.go +++ b/decort/resource_account.go @@ -428,7 +428,7 @@ func isChangedUser(els []interface{}, el interface{}) bool { elOldConv := elOld.(map[string]interface{}) elConv := el.(map[string]interface{}) 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)) { return true } diff --git a/decort/ssh_subresource.go b/decort/ssh_subresource.go deleted file mode 100644 index 1ac97a4..0000000 --- a/decort/ssh_subresource.go +++ /dev/null @@ -1,104 +0,0 @@ -/* -Copyright (c) 2019-2021 Digital Energy Cloud Solutions LLC. All Rights Reserved. -Author: Sergey Shubin, , - -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 -} diff --git a/decort/utility_extnet_default.go b/decort/utility_extnet_default.go index d07f306..a76b93c 100644 --- a/decort/utility_extnet_default.go +++ b/decort/utility_extnet_default.go @@ -32,7 +32,7 @@ import ( "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) urlValues := &url.Values{} diff --git a/decort/utility_rg.go b/decort/utility_rg.go index 803e4e4..118c898 100644 --- a/decort/utility_rg.go +++ b/decort/utility_rg.go @@ -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)) } - -func utilityResgroupGetDefaultGridID() (interface{}, error) { - if DefaultGridID > 0 { - return fmt.Sprintf("%d", DefaultGridID), nil - } - - return "", fmt.Errorf("utilityResgroupGetDefaultGridID: invalid default Grid ID %d", DefaultGridID) -}