Skip to content

CHEF-3954 Extended config block usage - Enabling kitchen usage with chef licensing#153

Draft
Nik08 wants to merge 6 commits intomainfrom
nm/config-block-usage-extended
Draft

CHEF-3954 Extended config block usage - Enabling kitchen usage with chef licensing#153
Nik08 wants to merge 6 commits intomainfrom
nm/config-block-usage-extended

Conversation

@Nik08
Copy link
Copy Markdown
Collaborator

@Nik08 Nik08 commented Aug 14, 2023

Description

Extended config block usage for following cases:

  1. To be able to set chef_license_key using config block. This case will be useful if someone tries to set chef license key value using kitchen.
  2. Ability to reset license_server_url using config block by introducing an additional parameter license_server_url_in_config_file. This case will be useful if someone tries to reset chef licensing server value using kitchen.

Related Issue

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Chore (non-breaking change that does not add functionality or fix an issue)

Checklist:

  • I have read the CONTRIBUTING document.
  • I have run the pre-merge tests locally and they pass.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.
  • All commits have been signed-off for the Developer Certificate of Origin.

@Nik08 Nik08 requested a review from ahasunos August 14, 2023 09:02
@Nik08 Nik08 changed the title Extended config block usage Extended config block usage - Enabling kitchen usage with chef licensing Aug 14, 2023
@Nik08 Nik08 changed the title Extended config block usage - Enabling kitchen usage with chef licensing CHEF-3954 Extended config block usage - Enabling kitchen usage with chef licensing Aug 14, 2023
Nik08 added 4 commits August 14, 2023 14:41
Signed-off-by: Nik08 <nikita.mathur@progress.com>
Signed-off-by: Nik08 <nikita.mathur@progress.com>
Signed-off-by: Nik08 <nikita.mathur@progress.com>
…l using config block

Signed-off-by: Nik08 <nikita.mathur@progress.com>
@Nik08 Nik08 force-pushed the nm/config-block-usage-extended branch from 76f53d1 to 15e5686 Compare August 14, 2023 09:12
Copy link
Copy Markdown
Contributor

@ahasunos ahasunos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have the following changes on inspec's end

diff --git a/lib/inspec/utils/licensing_config.rb b/lib/inspec/utils/licensing_config.rb
index 191e9865c..77b2eae19 100644
--- a/lib/inspec/utils/licensing_config.rb
+++ b/lib/inspec/utils/licensing_config.rb
@@ -6,4 +6,8 @@ ChefLicensing.configure do |config|
   config.chef_executable_name = "inspec"
   config.license_server_url = "https://licensing.chef.co/License"
   config.logger = Inspec::Log
+  config.license_server_url_check_in_file = false
+  config.license_server_url_in_config_file = true
+  config.license_server_url = "https://custom-licensing-server-2.com/License"
+  config.chef_license_key = "free-81547704-490b-4cb2-a7f3-ab0268d025d7-390"
 end

In my terminal, I have set the following environment:

❯ echo $CHEF_LICENSE_SERVER
https://licensing-acceptance.chef.co/License

Executing inspec for more than 2 runs shows the following behavior:

❯ bundle exec inspec exec
[2023-08-16T14:45:22+05:30] WARN: Connection failed to https://custom-licensing-server-2.com/License
[2023-08-16T14:45:22+05:30] ERROR: Unable to connect to the licensing server. InSpec requires server communication to operate.
The following URL(s) were tried:
1. https://custom-licensing-server-2.com/License


❯ bundle exec inspec exec

Test Summary: 0 successful, 0 failures, 0 skipped

❯ bundle exec inspec exec
[2023-08-16T14:45:33+05:30] WARN: Connection failed to https://custom-licensing-server-2.com/License
[2023-08-16T14:45:33+05:30] ERROR: Unable to connect to the licensing server. InSpec requires server communication to operate.
The following URL(s) were tried:
1. https://custom-licensing-server-2.com/License


❯ bundle exec inspec exec

Test Summary: 0 successful, 0 failures, 0 skipped

It executes in one run, and it gives an error in the other.

Edit

❯ cat ~/.chef/licenses.yaml
cat: /Users/sosaha/.chef/licenses.yaml: No such file or directory

❯ bundle exec inspec exec

Test Summary: 0 successful, 0 failures, 0 skipped

❯ cat ~/.chef/licenses.yaml
---
:file_format_version: 4.0.0
:licenses:
- :license_key: free-81547704-490b-4cb2-a7f3-ab0268d025d7-390
  :license_type: :free
  :update_time: '2023-08-16T14:48:33+05:30'
:license_server_url: https://licensing-acceptance.chef.co/License

❯ bundle exec inspec exec
[2023-08-16T14:48:44+05:30] WARN: Connection failed to https://custom-licensing-server-2.com/License
[2023-08-16T14:48:44+05:30] ERROR: Unable to connect to the licensing server. InSpec requires server communication to operate.
The following URL(s) were tried:
1. https://custom-licensing-server-2.com/License


❯ cat ~/.chef/licenses.yaml
---
:file_format_version: 4.0.0
:licenses:
- :license_key: free-81547704-490b-4cb2-a7f3-ab0268d025d7-390
  :license_type: :free
  :update_time: '2023-08-16T14:48:33+05:30'
:license_server_url: https://custom-licensing-server-2.com/License

It updates the license server url alternately, leading to the issue.

@Nik08
Copy link
Copy Markdown
Collaborator Author

Nik08 commented Aug 17, 2023

So I see you are trying to set the server URL through both system (using ENV) and also through the config block using license_server_url_in_config_file flag which is introduced to use the server URL value from the config block - since we do not always use to pick server url value from config block.
The config block is extended for the purpose of enabling the server URL to be set using Kitchen.

The flow goes like this using kitchen:

  • Server URL is passed through kitchen.yml
  • Used by inspec's runner and set in the config block along with a new flag license_server_url_in_config_file
  • Value is picked by chef-licensing through config block

So on your 2 runs, first it gave precedence to system value, and on a later run since the URLs are different, it gave precedence to config value.
Now are we expecting a different behavior out of this? Then this could be discussed:

  • Do we want to retain the system set server url value - even if someone is trying again to set it using config? ( This would be used via kitchen using kitchen.yml)
  • Given precedence to config values over system set server url values? In this case, we might have to retain config value over system value.
  • (Current Behaviour) Give precedence to system value, unless someone is trying to set it again using a config with a different URL value, via Kitchen through kitchen.yml.

Signed-off-by: Nik08 <nikita.mathur@progress.com>
Comment thread components/ruby/README.md
config.chef_executable_name = "inspec"
config.chef_entitlement_id = "chef123"
config.chef_license_key="free-t0832est-1111-1te1-b1e5-011t182test3-111"
config.license_server_url_in_config_file = true
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we can use set_license_server_url_fron_config_file or 'use_license_server_url_from_config_file`

Signed-off-by: Nik08 <nikita.mathur@progress.com>
Copy link
Copy Markdown
Contributor

@ahasunos ahasunos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Given I understand the usage of license_server_url_in_config_file. I approve the changes in this PR.

@Nik08 Nik08 self-assigned this Aug 31, 2023
@Nik08 Nik08 marked this pull request as draft March 26, 2026 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants