chef-cli 5.2.0 → 5.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5f07d3f568a94bf70e402ec732f96521233dafdf566b60bdc0ef9fad586e29af
4
- data.tar.gz: 6b060133bceeb79fde35c38a41b7c4b6e4a71520f1f631cf37d4f0942838c0ed
3
+ metadata.gz: 296f2275d23de7dca838ca9919a2ef33f99fcafab1876d3bea25d7c314738a77
4
+ data.tar.gz: 320ea6193c4d7af2754e88528f9916615e35f383392eef8cfdcfaa89c456cf45
5
5
  SHA512:
6
- metadata.gz: c429fdd87a900cd5c9178e44edc2eccf48a517a96aa0dd58de2adf5d1d9cdb0ddac522efeacb5676b9a12284bda262030fe8f5e65909ed40e21b5d3fb23845aa
7
- data.tar.gz: db8f7b5d1a073a314489315aa35db2554575bba13e37f1ac28c99f0795eb57233d0ae0beb1989f7aa98d0970ed0826cd96849367b1161ecf144d76fc224e9167
6
+ metadata.gz: 75673a37567263db2076636caa828cfa56ef03fc90b1fb0dbbc2eceaccf5d5b5ca8a39056b12363b3ef4d7eb1237c35919a7d8d5955771299c9826c759d7ad89
7
+ data.tar.gz: 8aed49647cc53678c60feae466ef554402420ec0df840565af1839cccf96e8cad8bb3ac422f249d87354ac1d091055334df94e21dc7677489de595183b65c4fe
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright:: Copyright (c) 2014-2018 Chef Software Inc.
2
+ # Copyright:: Copyright (c) Chef Software Inc.
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright:: Copyright (c) 2014-2019 Chef Software Inc.
2
+ # Copyright:: Copyright (c) Chef Software Inc.
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -71,6 +71,18 @@ module ChefCLI
71
71
  class MissingCookbookLockData < StandardError
72
72
  end
73
73
 
74
+ class PolicyfileMissingCookbookMetadata < StandardError
75
+ def initialize(cookbook_root)
76
+ super("Policyfile specified to use cookbook metadata, but neither #{cookbook_root}/metadata.rb or #{cookbook_root}/metadata.json was found.")
77
+ end
78
+ end
79
+
80
+ class PolicyfileBadCookbookMetadata < StandardError
81
+ def initialize(cookbook_root, e)
82
+ super("Cookbook metadata for cookbook at #{cookbook_root} could not be parsed:\n Original Exception: #{e}")
83
+ end
84
+ end
85
+
74
86
  class InvalidLockfile < StandardError
75
87
  end
76
88
 
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright:: Copyright (c) 2014-2019, Chef Software Inc.
2
+ # Copyright:: Copyright (c) Chef Software Inc.
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -138,6 +138,21 @@ module ChefCLI
138
138
  end
139
139
  end
140
140
 
141
+ def metadata
142
+ cookbook_root = storage_config.relative_paths_root
143
+ unless File.exist?(File.join(cookbook_root, "metadata.rb")) || File.exist?(File.join(cookbook_root, "metadata.json"))
144
+ raise PolicyfileMissingCookbookMetadata.new(cookbook_root)
145
+ end
146
+
147
+ begin
148
+ cookbook_name = CookbookMetadata.from_path(cookbook_root).cookbook_name
149
+ rescue Exception => e
150
+ raise PolicyfileBadCookbookMetadata.new(cookbook_root, e)
151
+ end
152
+ name cookbook_name if name.nil?
153
+ cookbook(cookbook_name, path: ".")
154
+ end
155
+
141
156
  def default
142
157
  @node_attributes.default
143
158
  end
@@ -16,5 +16,5 @@
16
16
  #
17
17
 
18
18
  module ChefCLI
19
- VERSION = "5.2.0".freeze
19
+ VERSION = "5.3.0".freeze
20
20
  end
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright:: Copyright (c) 2014-2018 Chef Software Inc.
2
+ # Copyright:: Copyright (c) Chef Software Inc.
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -80,6 +80,25 @@ describe ChefCLI::CookbookMetadata do
80
80
 
81
81
  end
82
82
 
83
+ context "and the cookbook has both a metadata.json and an (invalid) metadata.rb" do
84
+
85
+ let(:cookbook_root) { File.join(fixtures_path, "example_cookbook_both_metadata") }
86
+
87
+ it "has a name" do
88
+ expect(cookbook.name).to eq("example_cookbook")
89
+ expect(cookbook.cookbook_name).to eq("example_cookbook")
90
+ end
91
+
92
+ it "has a version" do
93
+ expect(cookbook.version).to eq("0.1.0")
94
+ end
95
+
96
+ it "has a map of dependencies" do
97
+ expect(cookbook.dependencies).to eq({})
98
+ end
99
+
100
+ end
101
+
83
102
  context "and the cookbook has no metadata" do
84
103
 
85
104
  let(:cookbook_root) { File.join(fixtures_path, "example_cookbook_no_metadata") }
@@ -0,0 +1,17 @@
1
+ .vagrant
2
+ Berksfile.lock
3
+ *~
4
+ *#
5
+ .#*
6
+ \#*#
7
+ .*.sw[a-z]
8
+ *.un~
9
+ /cookbooks
10
+
11
+ # Bundler
12
+ Gemfile.lock
13
+ bin/*
14
+ .bundle/*
15
+
16
+ .kitchen/
17
+ .kitchen.local.yml
@@ -0,0 +1,16 @@
1
+ ---
2
+ driver:
3
+ name: vagrant
4
+
5
+ provisioner:
6
+ name: chef_solo
7
+
8
+ platforms:
9
+ - name: ubuntu-12.04
10
+ - name: centos-6.4
11
+
12
+ suites:
13
+ - name: default
14
+ run_list:
15
+ - recipe[bar::default]
16
+ attributes:
@@ -0,0 +1,3 @@
1
+ source "https://supermarket.getchef.com"
2
+
3
+ metadata
@@ -0,0 +1,4 @@
1
+ # bar-cookbook
2
+
3
+ TODO: Enter the cookbook description here.
4
+
@@ -0,0 +1,96 @@
1
+ # Put files/directories that should be ignored in this file when uploading
2
+ # or sharing to the community site.
3
+ # Lines that start with '# ' are comments.
4
+
5
+ # OS generated files #
6
+ ######################
7
+ .DS_Store
8
+ Icon?
9
+ nohup.out
10
+ ehthumbs.db
11
+ Thumbs.db
12
+
13
+ # SASS #
14
+ ########
15
+ .sass-cache
16
+
17
+ # EDITORS #
18
+ ###########
19
+ \#*
20
+ .#*
21
+ *~
22
+ *.sw[a-z]
23
+ *.bak
24
+ REVISION
25
+ TAGS*
26
+ tmtags
27
+ *_flymake.*
28
+ *_flymake
29
+ *.tmproj
30
+ .project
31
+ .settings
32
+ mkmf.log
33
+
34
+ ## COMPILED ##
35
+ ##############
36
+ a.out
37
+ *.o
38
+ *.pyc
39
+ *.so
40
+ *.com
41
+ *.class
42
+ *.dll
43
+ *.exe
44
+ */rdoc/
45
+
46
+ # Testing #
47
+ ###########
48
+ .watchr
49
+ .rspec
50
+ spec/*
51
+ spec/fixtures/*
52
+ test/*
53
+ features/*
54
+ Guardfile
55
+ Procfile
56
+
57
+ # SCM #
58
+ #######
59
+ .git
60
+ */.git
61
+ .gitignore
62
+ .gitmodules
63
+ .gitconfig
64
+ .gitattributes
65
+ .svn
66
+ */.bzr/*
67
+ */.hg/*
68
+ */.svn/*
69
+
70
+ # Berkshelf #
71
+ #############
72
+ Berksfile
73
+ Berksfile.lock
74
+ cookbooks/*
75
+ tmp
76
+
77
+ # Cookbooks #
78
+ #############
79
+ CONTRIBUTING
80
+ CHANGELOG*
81
+
82
+ # Strainer #
83
+ ############
84
+ Colanderfile
85
+ Strainerfile
86
+ .colander
87
+ .strainer
88
+
89
+ # Vagrant #
90
+ ###########
91
+ .vagrant
92
+ Vagrantfile
93
+
94
+ # Travis #
95
+ ##########
96
+ .travis.yml
@@ -0,0 +1,5 @@
1
+ {
2
+ "name": "example_cookbook",
3
+ "version": "0.1.0"
4
+ }
5
+
@@ -0,0 +1,9 @@
1
+ # This is vitally important for cookbooks that ship with context-dependent
2
+ # metadata.rb (to do things like auto incrementing semantic versioning) where
3
+ # the metadata.json means the cookbook is 'finalized' and must be authoritative.
4
+ # We need to never try to parse metadata.rb if the metadata.json exists. It isn't
5
+ # sufficient to simply not use the metadata.rb file, but we must allow the
6
+ # metadata.rb to have an invalid parse due to LoadErrors in the environment where
7
+ # the cookbook is being loaded.
8
+
9
+ raise "we never want to read the metadata.rb if metadata.json exists"
@@ -0,0 +1,8 @@
1
+ #
2
+ # Cookbook Name:: example_cookbook
3
+ # Recipe:: default
4
+ #
5
+ # Copyright (C) 2014
6
+ #
7
+ #
8
+ #
@@ -1,5 +1,5 @@
1
1
  #
2
- # Copyright:: Copyright (c) 2014-2018, Chef Software Inc.
2
+ # Copyright:: Copyright (c) Chef Software Inc.
3
3
  # License:: Apache License, Version 2.0
4
4
  #
5
5
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -555,6 +555,72 @@ describe ChefCLI::PolicyfileCompiler do
555
555
 
556
556
  end
557
557
 
558
+ describe "the metadata DSL keyword used in a cookbook with metadata" do
559
+ let(:policyfile_rb) do
560
+ <<-EOH
561
+ run_list "foo"
562
+ metadata
563
+ EOH
564
+ end
565
+ it "reads the metadata from the current cookbook" do
566
+ expect(File).to receive(:exist?).with("./metadata.rb").and_return(true)
567
+ expect(ChefCLI::CookbookMetadata).to receive(:from_path).and_return(double(cookbook_name: "foo"))
568
+ expect(policyfile.errors.size).to eq(0)
569
+ expect(policyfile.errors.first).to eq(nil)
570
+ end
571
+ end
572
+
573
+ describe "the metadata DSL keyword used in a cookbook without metadata" do
574
+ let(:policyfile_rb) do
575
+ <<-EOH
576
+ run_list "foo"
577
+ metadata
578
+ EOH
579
+ end
580
+ it "throws a missing cookbook metadata error" do
581
+ expected = <<~EOH
582
+ Evaluation of policyfile 'TestPolicyfile.rb' raised an exception
583
+ Exception: ChefCLI::PolicyfileMissingCookbookMetadata "Policyfile specified to use cookbook metadata, but neither ./metadata.rb or ./metadata.json was found."
584
+
585
+ Relevant Code:
586
+ 2: metadata
587
+
588
+ Backtrace:
589
+ TestPolicyfile.rb:2:in `eval_policyfile'
590
+ EOH
591
+ expect(File).to receive(:exist?).with("./metadata.rb").and_return(false)
592
+ expect(File).to receive(:exist?).with("./metadata.json").and_return(false)
593
+ expect(policyfile.errors.size).to eq(1)
594
+ expect(policyfile.errors.first).to eq(expected)
595
+ end
596
+ end
597
+
598
+ describe "the metadata DSL keyword used in a cookbook with bad metadata" do
599
+ let(:policyfile_rb) do
600
+ <<-EOH
601
+ run_list "foo"
602
+ metadata
603
+ EOH
604
+ end
605
+ it "throws a bad cookbook metadata error" do
606
+ expected = <<~EOH
607
+ Evaluation of policyfile 'TestPolicyfile.rb' raised an exception
608
+ Exception: ChefCLI::PolicyfileBadCookbookMetadata "Cookbook metadata for cookbook at . could not be parsed:
609
+ Original Exception: No such file or directory @ rb_sysopen - ./metadata.json"
610
+
611
+ Relevant Code:
612
+ 2: metadata
613
+
614
+ Backtrace:
615
+ TestPolicyfile.rb:2:in `eval_policyfile'
616
+ EOH
617
+ expect(File).to receive(:exist?).with("./metadata.rb").and_return(true)
618
+ expect(File).to receive(:exist?).with("./metadata.json").and_return(true)
619
+ expect(policyfile.errors.size).to eq(1)
620
+ expect(policyfile.errors.first).to eq(expected)
621
+ end
622
+ end
623
+
558
624
  describe "defining attributes" do
559
625
 
560
626
  let(:policyfile_rb) do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.0
4
+ version: 5.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chef Software, Inc.
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-07-01 00:00:00.000000000 Z
11
+ date: 2021-07-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mixlib-cli
@@ -485,6 +485,14 @@ files:
485
485
  - spec/unit/fixtures/example_cookbook/chefignore
486
486
  - spec/unit/fixtures/example_cookbook/metadata.rb
487
487
  - spec/unit/fixtures/example_cookbook/recipes/default.rb
488
+ - spec/unit/fixtures/example_cookbook_both_metadata/.gitignore
489
+ - spec/unit/fixtures/example_cookbook_both_metadata/.kitchen.yml
490
+ - spec/unit/fixtures/example_cookbook_both_metadata/Berksfile
491
+ - spec/unit/fixtures/example_cookbook_both_metadata/README.md
492
+ - spec/unit/fixtures/example_cookbook_both_metadata/chefignore
493
+ - spec/unit/fixtures/example_cookbook_both_metadata/metadata.json
494
+ - spec/unit/fixtures/example_cookbook_both_metadata/metadata.rb
495
+ - spec/unit/fixtures/example_cookbook_both_metadata/recipes/default.rb
488
496
  - spec/unit/fixtures/example_cookbook_metadata_json_only/.gitignore
489
497
  - spec/unit/fixtures/example_cookbook_metadata_json_only/.kitchen.yml
490
498
  - spec/unit/fixtures/example_cookbook_metadata_json_only/Berksfile
@@ -700,6 +708,14 @@ test_files:
700
708
  - spec/unit/fixtures/example_cookbook/chefignore
701
709
  - spec/unit/fixtures/example_cookbook/metadata.rb
702
710
  - spec/unit/fixtures/example_cookbook/recipes/default.rb
711
+ - spec/unit/fixtures/example_cookbook_both_metadata/.gitignore
712
+ - spec/unit/fixtures/example_cookbook_both_metadata/.kitchen.yml
713
+ - spec/unit/fixtures/example_cookbook_both_metadata/Berksfile
714
+ - spec/unit/fixtures/example_cookbook_both_metadata/README.md
715
+ - spec/unit/fixtures/example_cookbook_both_metadata/chefignore
716
+ - spec/unit/fixtures/example_cookbook_both_metadata/metadata.json
717
+ - spec/unit/fixtures/example_cookbook_both_metadata/metadata.rb
718
+ - spec/unit/fixtures/example_cookbook_both_metadata/recipes/default.rb
703
719
  - spec/unit/fixtures/example_cookbook_metadata_json_only/.gitignore
704
720
  - spec/unit/fixtures/example_cookbook_metadata_json_only/.kitchen.yml
705
721
  - spec/unit/fixtures/example_cookbook_metadata_json_only/Berksfile