knife-tarsnap 0.1.1 → 0.1.2

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.
data/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Provides a chef cookbook with LWRP's to take directory snapshots and maintain retention schedules. Includes a knife plugin for managing tarsnap keys, listing backups, and restoring files.
4
4
 
5
- Backup services are handled by [Colin Percival's](https://twitter.com/cperciva) excellent [tarsnap](https://www.tarsnap.com/).
5
+ Backup services are handled by [Colin Percival](https://twitter.com/cperciva)'s excellent [tarsnap](https://www.tarsnap.com/).
6
6
 
7
7
 
8
8
  ## Installation
@@ -37,7 +37,7 @@ Or install it yourself as:
37
37
 
38
38
  $ gem install knife-tarsnap
39
39
 
40
- Alternatively, and add this line to your application's Gemfile:
40
+ Alternatively, add this line to your application's Gemfile:
41
41
 
42
42
  gem 'knife-tarsnap', :path => 'cookbooks/tarsnap/knife-tarsnap'
43
43
 
@@ -50,7 +50,7 @@ And then execute:
50
50
 
51
51
  ### Backing up node data
52
52
 
53
- Create a recipe to define your tarnsap resources, like this:
53
+ Create a recipe to define your tarsnap resources, like this:
54
54
 
55
55
  ```ruby
56
56
  # my-app::backups
@@ -242,7 +242,8 @@ You need to keep a copy of your keys somewhere safe. If you lose them, then it i
242
242
 
243
243
  ## License
244
244
 
245
- Author:: Scott Sanders (ssanders@taximagic.com)
245
+ Author:: Scott Sanders (scott@jssjr.com)
246
+ Author:: Greg Fitzgerald (greg@gregf.org)
246
247
 
247
248
  Copyright:: Copyright (c) 2013 RideCharge, Inc.
248
249
 
@@ -53,8 +53,9 @@ class Chef
53
53
  end
54
54
  end
55
55
 
56
- # Convenience methods for options
56
+ ## Convenience methods for options
57
57
 
58
+ # Returns the tarsnap account username or throw an exception.
58
59
  def tarsnap_username
59
60
  if Chef::Config[:knife][:tarsnap_username]
60
61
  Chef::Config[:knife][:tarsnap_username]
@@ -63,6 +64,7 @@ class Chef
63
64
  end
64
65
  end
65
66
 
67
+ # Returns the tarsnap account password, or prompt the user for input.
66
68
  def tarsnap_password
67
69
  if Chef::Config[:knife][:tarsnap_password].nil?
68
70
  Chef::Config[:knife][:tarsnap_password] = ui.ask('Tarsnap Password: ') { |q| q.echo = '*' }
@@ -70,41 +72,50 @@ class Chef
70
72
  Chef::Config[:knife][:tarsnap_password]
71
73
  end
72
74
 
75
+ # Returns the name of the data bag used to store tarsnap keys.
73
76
  def tarsnap_data_bag
74
77
  Chef::Config[:knife][:tarsnap_data_bag] || config[:tarsnap_data_bag]
75
78
  end
76
79
 
77
- # Required tools
80
+ ## Required tools
78
81
 
82
+ # Returns the path of the tarsnap-keygen command line binary.
79
83
  def keygen_tool
80
84
  @_keygen_path || @_keygen_path = which('tarsnap-keygen')
81
85
  end
82
86
 
87
+ # Returns the path of the tarsnap command line binary.
83
88
  def tarsnap_tool
84
89
  @_tarsnap_path || @_tarsnap_path = which('tarsnap')
85
90
  end
86
91
 
87
- # Helpers
92
+ ## Helpers
88
93
 
94
+ # Normalize the FQDN by replacing dots (.) with underscores (_).
89
95
  def canonicalize(fqdn)
90
96
  fqdn.gsub(".","_")
91
97
  end
92
98
 
99
+ # Return the list of nodes from the data bag marked as pending.
93
100
  def pending_nodes
101
+ Shell::Extensions.extend_context_object(self)
94
102
  @_pending_nodes || @_pending_nodes =
95
- Chef::DataBag.load(tarsnap_data_bag).keep_if{|k,v| k =~ /^__/}.map{|k,v| k.gsub(/^__/, '').gsub("_",".")}
103
+ nodes.find('tarsnap_pending:true').map{|n| n.fqdn}
96
104
  end
97
105
 
106
+ # Return the list of nodes from the data bag marked as having keys.
98
107
  def tarsnap_nodes
99
108
  @_tarsnap_nodes || @_tarsnap_nodes =
100
109
  Chef::DataBag.load(tarsnap_data_bag).keep_if{|k,v| k !~ /^__/}.map{|k,v| k.gsub("_",".")}
101
110
  end
102
111
 
112
+ # Convenience method for returning a Chef::Node object from its FQDN.
103
113
  def fetch_node(fqdn)
104
114
  Shell::Extensions.extend_context_object(self)
105
115
  nodes.find("fqdn:#{fqdn}").first
106
116
  end
107
117
 
118
+ # Returns the tarsnap key for a given node's FQDN.
108
119
  def fetch_key(fqdn)
109
120
  bag_item = fetch_tarsnap_bag_item(fqdn)
110
121
  if bag_item
@@ -114,16 +125,21 @@ class Chef
114
125
  end
115
126
  end
116
127
 
128
+ # Returns a boolean indicating if the node has a tarsnap key and is ready for use, or not.
117
129
  def is_a_tarsnap_node?(fqdn)
118
130
  tarsnap_nodes.include?(fqdn)
119
131
  end
120
132
 
133
+ # Remove the data bag entry for a pending node.
121
134
  def remove_pending_node(fqdn)
122
- rest.delete_rest("data/#{tarsnap_data_bag}/__#{canonicalize(fqdn)}")
135
+ n = nodes.find("fqdn:#{fqdn}").first
136
+ n.set.delete('tarsnap_pending')
137
+ n.save
123
138
  end
124
139
 
125
140
  private
126
141
 
142
+ # Returns the path for the requested binary.
127
143
  def which(binary)
128
144
  which_cmd = "which #{binary}"
129
145
  which_shell = Mixlib::ShellOut.new(which_cmd)
@@ -134,6 +150,7 @@ class Chef
134
150
  which_shell.stdout.chomp
135
151
  end
136
152
 
153
+ # Fetch the tarsnap keys data bag item for a node and return it.
137
154
  def fetch_tarsnap_bag_item(fqdn)
138
155
  begin
139
156
  Chef::EncryptedDataBagItem.load(tarsnap_data_bag, canonicalize(fqdn))
@@ -1,5 +1,5 @@
1
1
  module Knife
2
2
  module Tarsnap
3
- VERSION = "0.1.1"
3
+ VERSION = "0.1.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-tarsnap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-08 00:00:00.000000000 Z
12
+ date: 2013-08-08 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: chef
@@ -78,4 +78,3 @@ summary: Provides a chef cookbook with LWRP's to directory snapshots and maintai
78
78
  retention schedules. Includes a knife plugin for managing tarsnap keys, listing
79
79
  backups, and restoring files.
80
80
  test_files: []
81
- has_rdoc: