knife-ec-backup 3.0.5 → 3.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -298,6 +298,9 @@ class Chef
298
298
  chef_fs_copy_pattern(path, chef_fs_config)
299
299
  end
300
300
 
301
+ # Apply frozen status to cookbooks after they are uploaded
302
+ restore_cookbook_frozen_status(name, chef_fs_config)
303
+
301
304
  # restore clients to groups, using the pivotal user again
302
305
  Chef::Config[:node_name] = 'pivotal'
303
306
  groups.each do |group|
@@ -377,6 +380,61 @@ class Chef
377
380
  Chef::Log.warn "Could not find #{group.display_path} on disk. Will not restore."
378
381
  end
379
382
 
383
+ # Restore cookbook frozen status from status.json files
384
+ def restore_cookbook_frozen_status(org_name, chef_fs_config)
385
+ return if config[:skip_frozen_cookbook_status]
386
+
387
+ ui.msg "Restoring cookbook frozen status"
388
+ cookbooks_path = "#{dest_dir}/organizations/#{org_name}/cookbooks"
389
+
390
+ return unless File.directory?(cookbooks_path)
391
+
392
+ Dir.foreach(cookbooks_path) do |cookbook_entry|
393
+ next if cookbook_entry == '.' || cookbook_entry == '..'
394
+ cookbook_path = File.join(cookbooks_path, cookbook_entry)
395
+ next unless File.directory?(cookbook_path)
396
+
397
+ # cookbook_entry is in format "cookbook_name-version"
398
+ # Extract cookbook name and version
399
+ if cookbook_entry =~ /^(.+)-(\d+\.\d+\.\d+.*)$/
400
+ cookbook_name = $1
401
+ version = $2
402
+
403
+ status_file = File.join(cookbook_path, 'status.json')
404
+ next unless File.exist?(status_file)
405
+
406
+ begin
407
+ status_data = JSON.parse(File.read(status_file))
408
+ if status_data['frozen'] == true
409
+ freeze_cookbook(cookbook_name, version, org_name)
410
+ end
411
+ rescue JSON::ParserError => e
412
+ ui.warn "Failed to parse status.json for #{cookbook_name} #{version}: #{e.message}"
413
+ rescue => e
414
+ ui.warn "Failed to restore frozen status for #{cookbook_name} #{version}: #{e.message}"
415
+ end
416
+ end
417
+ end
418
+ end
419
+
420
+ # Freeze a cookbook on the Chef Server
421
+ def freeze_cookbook(cookbook_name, version, org_name)
422
+ ui.msg "Freezing cookbook #{cookbook_name} version #{version}"
423
+
424
+ # Get the current cookbook manifest
425
+ manifest = rest.get("organizations/#{org_name}/cookbooks/#{cookbook_name}/#{version}")
426
+
427
+ if manifest['frozen?'] # Ignore if already frozen
428
+ ui.warn "Freezing cookbook #{cookbook_name} version #{version} skipped since it is already frozen!"
429
+ return
430
+ end
431
+
432
+ rest.put("organizations/#{org_name}/cookbooks/#{cookbook_name}/#{version}?freeze=true", manifest.tap { |h| h["frozen?"] = true })
433
+ rescue Net::HTTPClientException => ex
434
+ ui.warn "Failed to freeze cookbook #{cookbook_name} #{version}: #{ex.message}"
435
+ knife_ec_error_handler.add(ex)
436
+ end
437
+
380
438
  PERMISSIONS = %w{create read update delete grant}.freeze
381
439
  def put_acl(rest, url, acls)
382
440
  old_acls = rest.get(url)
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Author:: Steven Danna (<steve@chef.io>)
3
- # Copyright:: Copyright (c) 2015 Chef Software, Inc.
3
+ # Copyright:: Copyright (c) 2013-2025 Progress Software Corporation and/or its subsidiaries or affiliates. All Rights Reserved.
4
4
  # License:: Apache License, Version 2.0
5
5
  #
6
6
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,4 +1,4 @@
1
1
  # when you change this to double quotes, also update .expeditor/update_version.sh
2
2
  module KnifeECBackup
3
- VERSION = '3.0.5'
3
+ VERSION = '3.0.9'
4
4
  end