Skip to content

Instantly share code, notes, and snippets.

View jonlives's full-sized avatar

Jon Cowie jonlives

View GitHub Profile
<command>
<ident value="only_if">
<pos line="38" column="2"/>
</ident>
<args_add_block value="false">
<args_add>
<args_new/>
<string_literal>
<string_add>
<string_add>
% trafficserver> show:cache-stats
Bytes Used --- 0 GB
Cache Size --- 9 GB
--RAM Cache--
Total Bytes -- 10737418240
Bytes Used --- 0
Hits --------- 0
Misses ------- 0
--Lookups--
<args_add_block value="false">
<args_add>
<args_add>
<args_new/>
<symbol_literal>
<symbol>
<ident value="restart">
<pos line="12" column="12"/>
</ident>
</symbol>
rule "ETSY005", "Action :restart sent to a core service" do
tags %w{correctness recipe etsy}
recipe do |ast, filename|
res = ast.xpath('//command[ident/@value = "notifies"]/args_add_block[descendant::symbol/ident/@value="restart"]/descendant::method_add_arg[fcall/ident/@value="resources"]/descendant::assoc_new[symbol/ident/@value="service"]/descendant::tstring_content')
res.each do |notifies|
if notifies.attribute('value').to_s.include?('nscd')
[match(res)]
end
end
end
<opt>
<stmts_add>
<stmts_add>
<stmts_new/>
<method_add_block>
<command>
<ident value="service">
<pos line="1" column="0"/>
</ident>
<args_add_block value="false">
[7] pry(#<FoodCritic::RuleDsl>)> resource_attributes(cmd)
=> {:name=>"/etc/nscd.conf",
"backup"=>"",
"source"=>"nscd.conf",
"owner"=>"root",
"group"=>"root",
"mode"=>"",
"notifies"=>:restart}
execute "generate_csr" do
user "root"
cwd "/tmp/"
command "<snip>"
only_if {!File.exists?(foo) || (File.exists?(bar) && File.mtime(baz) < last_changedate)}
end
rule "ETSY004", "Execute resource defined without conditional or action :nothing" do
tags %w{correctness recipe etsy}
recipe do |ast|
pres = find_resources(ast, :type => 'execute').find_all do |cmd|
not_if = (resource_attribute(cmd, 'not_if') || "").to_s
only_if = (resource_attribute(cmd, 'only_if') || "").to_s
creates = (resource_attribute(cmd, 'creates') || "").to_s
action = creates = (resource_attribute(cmd, 'action') || "")
(not_if.empty? && only_if.empty? && creates.empty?)
end.map{|cmd| match(cmd)}
require 'chef/knife'
module KnifeSpork
class Testy < Chef::Knife
banner "knife test"
def run
@response = ui.ask_question("What is your name?")
r = gem_package "sys-proctable" do
action :nothing
end
r2 = gem_package "sys-filesystem" do
action :nothing
end
r.run_action(:install)
r2.run_action(:install)