From ed97d7c0c057fd906d72c9c0092e40e81bb74df5 Mon Sep 17 00:00:00 2001 From: Ramesh Sencha Date: Wed, 21 Feb 2024 20:37:08 +0530 Subject: [PATCH] (CAT-1728) - Unable to use password function as deferred function --- .github/workflows/release.yml | 2 +- .rubocop.yml | 6 ++++++ .vscode/extensions.json | 2 +- Gemfile | 7 +++---- REFERENCE.md | 19 ------------------- lib/puppet/functions/sqlserver/password.rb | 13 ------------- manifests/login.pp | 5 ++++- manifests/user.pp | 5 ++++- metadata.json | 2 +- spec/functions/password_spec.rb | 8 -------- 10 files changed, 20 insertions(+), 49 deletions(-) delete mode 100644 lib/puppet/functions/sqlserver/password.rb delete mode 100644 spec/functions/password_spec.rb diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 0b7b8a05..4b3b80fc 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -2,7 +2,7 @@ name: "Publish module" on: workflow_dispatch: - + jobs: release: uses: "puppetlabs/cat-github-actions/.github/workflows/module_release.yml@main" diff --git a/.rubocop.yml b/.rubocop.yml index 7a66e083..e6bd5af8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -529,6 +529,8 @@ Lint/DuplicateBranch: Enabled: false Lint/DuplicateMagicComment: Enabled: false +Lint/DuplicateMatchPattern: + Enabled: false Lint/DuplicateRegexpCharacterClassElement: Enabled: false Lint/EmptyBlock: @@ -645,6 +647,8 @@ Style/ComparableClamp: Enabled: false Style/ConcatArrayLiterals: Enabled: false +Style/DataInheritance: + Enabled: false Style/DirEmpty: Enabled: false Style/DocumentDynamicEvalDefinition: @@ -713,6 +717,8 @@ Style/RedundantHeredocDelimiterQuotes: Enabled: false Style/RedundantInitialize: Enabled: false +Style/RedundantLineContinuation: + Enabled: false Style/RedundantSelfAssignmentBranch: Enabled: false Style/RedundantStringEscape: diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 2f1e4f73..6da8d472 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,6 +1,6 @@ { "recommendations": [ "puppet.puppet-vscode", - "rebornix.Ruby" + "Shopify.ruby-lsp" ] } diff --git a/Gemfile b/Gemfile index b044d8e1..d6e99877 100644 --- a/Gemfile +++ b/Gemfile @@ -22,16 +22,15 @@ group :development do gem "racc", '~> 1.4.0', require: false if Gem::Requirement.create(['>= 2.7.0', '< 3.0.0']).satisfied_by?(Gem::Version.new(RUBY_VERSION.dup)) gem "voxpupuli-puppet-lint-plugins", '~> 5.0', require: false gem "facterdb", '~> 1.18', require: false - gem "metadata-json-lint", '~> 3.0', require: false + gem "metadata-json-lint", '~> 4.0', require: false gem "puppetlabs_spec_helper", '~> 6.0', require: false gem "rspec-puppet-facts", '~> 2.0', require: false - gem "codecov", '~> 0.2', require: false gem "dependency_checker", '~> 1.0.0', require: false gem "parallel_tests", '= 3.12.1', require: false gem "pry", '~> 0.10', require: false - gem "simplecov-console", '~> 0.5', require: false + gem "simplecov-console", '~> 0.9', require: false gem "puppet-debugger", '~> 1.0', require: false - gem "rubocop", '= 1.48.1', require: false + gem "rubocop", '~> 1.50.0', require: false gem "rubocop-performance", '= 1.16.0', require: false gem "rubocop-rspec", '= 2.19.0', require: false gem "puppet-strings", '~> 4.0', require: false diff --git a/REFERENCE.md b/REFERENCE.md index 42183610..b84d6da1 100644 --- a/REFERENCE.md +++ b/REFERENCE.md @@ -25,7 +25,6 @@ ### Functions * [`sqlserver::partial_params_args`](#sqlserver--partial_params_args): this function populates and returns the string of arguments which later gets injected in template. -* [`sqlserver::password`](#sqlserver--password): This function exists for usage of a role password that is a deferred function * [`sqlserver_is_domain_or_local_user`](#sqlserver_is_domain_or_local_user) * [`sqlserver_upcase`](#sqlserver_upcase) * [`sqlserver_validate_hash_uniq_values`](#sqlserver_validate_hash_uniq_values) @@ -1236,24 +1235,6 @@ Optional[Enum['ON', 'OFF']] $nested_triggers Optional[Enum['ON', 'OFF']] $transform_noise_words Integer[1753, 9999] $two_digit_year_cutoff -### `sqlserver::password` - -Type: Ruby 4.x API - -This function exists for usage of a role password that is a deferred function - -#### `sqlserver::password(Optional[Any] $pass)` - -This function exists for usage of a role password that is a deferred function - -Returns: `Any` - -##### `pass` - -Data type: `Optional[Any]` - - - ### `sqlserver_is_domain_or_local_user` Type: Ruby 3.x API diff --git a/lib/puppet/functions/sqlserver/password.rb b/lib/puppet/functions/sqlserver/password.rb deleted file mode 100644 index 8abf0b88..00000000 --- a/lib/puppet/functions/sqlserver/password.rb +++ /dev/null @@ -1,13 +0,0 @@ -# frozen_string_literal: true - -# This function exists for usage of a role password that is a deferred function -Puppet::Functions.create_function(:'sqlserver::password') do - dispatch :password do - optional_param 'Any', :pass - return_type 'Any' - end - - def password(pass) - pass - end -end diff --git a/manifests/login.pp b/manifests/login.pp index fd2f1442..a081f462 100644 --- a/manifests/login.pp +++ b/manifests/login.pp @@ -80,7 +80,10 @@ $create_delete_login_parameters = { 'disabled' => $disabled, 'login' => $login, - 'password' => Deferred('sqlserver::password', [$password]), + 'password' => $password ? { + undef => undef, + default => Deferred('sprintf', [$password]), + }, 'check_expiration' => $check_expiration, 'check_policy' => $check_policy, 'default_language' => $default_language, diff --git a/manifests/user.pp b/manifests/user.pp index eb92a1c6..e2f8503b 100644 --- a/manifests/user.pp +++ b/manifests/user.pp @@ -65,7 +65,10 @@ if $create_delete == 'create' { $create_delete_user_parameters = { 'database' => $database, - 'password' => Deferred('sqlserver::password', [$password]), + 'password' => $password ? { + undef => undef, + default => Deferred('sprintf', [$password]), + }, 'user' => $user, 'login' => $login, 'default_schema' => $default_schema, diff --git a/metadata.json b/metadata.json index 90f91541..d977db1f 100644 --- a/metadata.json +++ b/metadata.json @@ -50,5 +50,5 @@ ], "pdk-version": "3.0.0", "template-url": "https://github.com/puppetlabs/pdk-templates.git#main", - "template-ref": "heads/main-0-g79a2f93" + "template-ref": "heads/main-0-g0f7378b" } diff --git a/spec/functions/password_spec.rb b/spec/functions/password_spec.rb deleted file mode 100644 index 54010644..00000000 --- a/spec/functions/password_spec.rb +++ /dev/null @@ -1,8 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe 'sqlserver::password' do - it { is_expected.to run.with_params('password').and_return('password') } - it { is_expected.to run.with_params(nil).and_return(nil) } -end