knife-reporting 0.3.1 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,22 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2013-2014 Chef Software, Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'chef/reporting/knife_helpers'
19
+
1
20
  class Chef
2
21
  class Knife
3
22
  class RunsList < Chef::Knife
@@ -8,10 +27,9 @@ class Chef
8
27
  # modules be loaded.
9
28
  require 'time'
10
29
  require 'date'
11
- require 'chef/knife/reporting_helpers'
12
30
  end
13
31
 
14
- include ReportingHelpers
32
+ include Chef::Reporting::KnifeHelpers
15
33
 
16
34
  banner "knife runs list [<node name>]"
17
35
 
@@ -87,7 +105,7 @@ class Chef
87
105
  end
88
106
  end
89
107
 
108
+ end
90
109
  end
91
110
  end
92
- end
93
111
 
@@ -1,3 +1,22 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2013-2014 Chef Software, Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ require 'chef/reporting/knife_helpers'
19
+
1
20
  class Chef
2
21
  class Knife
3
22
  class RunsShow < Chef::Knife
@@ -8,10 +27,9 @@ class Chef
8
27
  # modules be loaded.
9
28
  require 'time'
10
29
  require 'date'
11
- require 'chef/knife/reporting_helpers'
12
30
  end
13
31
 
14
- include ReportingHelpers
32
+ include Chef::Reporting::KnifeHelpers
15
33
 
16
34
  banner "knife runs show <run id>"
17
35
 
@@ -0,0 +1,93 @@
1
+ #
2
+ # Copyright:: Copyright (c) 2013-2014 Chef Software, Inc.
3
+ # License:: Apache License, Version 2.0
4
+ #
5
+ # Licensed under the Apache License, Version 2.0 (the "License");
6
+ # you may not use this file except in compliance with the License.
7
+ # You may obtain a copy of the License at
8
+ #
9
+ # http://www.apache.org/licenses/LICENSE-2.0
10
+ #
11
+ # Unless required by applicable law or agreed to in writing, software
12
+ # distributed under the License is distributed on an "AS IS" BASIS,
13
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
+ # See the License for the specific language governing permissions and
15
+ # limitations under the License.
16
+ #
17
+
18
+ class Chef
19
+ module Reporting
20
+ module KnifeHelpers
21
+
22
+ # Need the unless guard b/c this code is dynamically loaded
23
+ # and can result in ruby warnings if it attempts to define the
24
+ # constant again
25
+ SECONDS_IN_24HOURS = 86400 unless const_defined?(:SECONDS_IN_24HOURS)
26
+ # Approximate, b/c of course the length of a month can vary
27
+ SECONDS_IN_3MONTHS = 7889230 unless const_defined?(:SECONDS_IN_3MONTHS)
28
+
29
+ def uuid?(run_id)
30
+ if run_id =~ /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/
31
+ return false
32
+ else
33
+ return true
34
+ end
35
+ end
36
+
37
+ def apply_time_args()
38
+ if config[:start_time] && config[:end_time]
39
+ start_time, end_time = convert_to_unix_timestamps()
40
+ else
41
+ start_time, end_time = last_24hours_time_window()
42
+ end
43
+
44
+ return start_time, end_time
45
+ end
46
+
47
+ def last_24hours_time_window()
48
+ # Time is calculated as a unix timestamp
49
+ end_time = Time.now.to_i
50
+ start_time = end_time - SECONDS_IN_24HOURS
51
+ return start_time, end_time
52
+ end
53
+
54
+ def check_start_and_end_times_provided()
55
+ if config[:start_time] && !config[:end_time]
56
+ ui.error("The start_time option was provided, but the end_time option was not. If one is provided, the other is required.")
57
+ exit 1
58
+ elsif config[:end_time] && !config[:start_time]
59
+ ui.error("The end_time option was provided, but the start_time option was not. If one is provided, the other is required.")
60
+ exit 1
61
+ end
62
+ end
63
+
64
+ def convert_to_unix_timestamps()
65
+ if config[:unix_timestamps]
66
+ start_time = config[:start_time].to_i
67
+ end_time = config[:end_time].to_i
68
+ else
69
+ # Take user supplied input, assumes it is in a valid date format,
70
+ # convert to a date object to ensure we have the proper date format for
71
+ # passing to the time object (but converting is not a validation step,
72
+ # so bad user input will still be bad)
73
+ # then convert to a time object, and then convert to a unix timestamp
74
+ # An error could potentially be thrown if the conversions don't work
75
+ # This does work on windows - to_i on time even on windows still returns a unix timestamp
76
+ # Verified on ruby 1.9.3 on a windows 2000 ami on aws
77
+ start_time = Time.parse(Date.strptime(config[:start_time], '%m-%d-%Y').to_s).to_i
78
+ end_time = Time.parse(Date.strptime(config[:end_time], '%m-%d-%Y').to_s).to_i
79
+ end
80
+
81
+ return start_time, end_time
82
+ end
83
+
84
+ def check_3month_window(start_time, end_time)
85
+ # start_time and end_time are unix timestamps
86
+ if (end_time - start_time) > SECONDS_IN_3MONTHS
87
+ ui.error("Requesting information for more than three months at a time is disallowed. Please try a smaller timeframe.")
88
+ exit 1
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: knife-reporting
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-12-10 00:00:00.000000000 Z
12
+ date: 2014-02-03 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: mixlib-cli
16
- requirement: &70220669244540 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,7 +21,12 @@ dependencies:
21
21
  version: 1.2.2
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70220669244540
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.2.2
25
30
  description: Knife plugin for Opscode Reporting
26
31
  email: matthew@opscode.com
27
32
  executables: []
@@ -33,9 +38,9 @@ files:
33
38
  - LICENSE
34
39
  - README.md
35
40
  - Rakefile
36
- - lib/chef/knife/reporting_helpers.rb
37
41
  - lib/chef/knife/runs_list.rb
38
42
  - lib/chef/knife/runs_show.rb
43
+ - lib/chef/reporting/knife_helpers.rb
39
44
  homepage: http://www.opscode.com
40
45
  licenses: []
41
46
  post_install_message:
@@ -56,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
56
61
  version: '0'
57
62
  requirements: []
58
63
  rubyforge_project:
59
- rubygems_version: 1.8.11
64
+ rubygems_version: 1.8.23
60
65
  signing_key:
61
66
  specification_version: 3
62
67
  summary: Knife plugin for Opscode Reporting
@@ -1,73 +0,0 @@
1
- module ReportingHelpers
2
-
3
- # Need the unless guard b/c this code is dynamically loaded
4
- # and can result in ruby warnings if it attempts to define the
5
- # constant again
6
- SECONDS_IN_24HOURS = 86400 unless const_defined?(:SECONDS_IN_24HOURS)
7
- # Approximate, b/c of course the length of a month can vary
8
- SECONDS_IN_3MONTHS = 7889230 unless const_defined?(:SECONDS_IN_3MONTHS)
9
-
10
- def uuid?(run_id)
11
- if run_id =~ /^[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}$/
12
- return false
13
- else
14
- return true
15
- end
16
- end
17
-
18
- def apply_time_args()
19
- if config[:start_time] && config[:end_time]
20
- start_time, end_time = convert_to_unix_timestamps()
21
- else
22
- start_time, end_time = last_24hours_time_window()
23
- end
24
-
25
- return start_time, end_time
26
- end
27
-
28
- def last_24hours_time_window()
29
- # Time is calculated as a unix timestamp
30
- end_time = Time.now.to_i
31
- start_time = end_time - SECONDS_IN_24HOURS
32
- return start_time, end_time
33
- end
34
-
35
- def check_start_and_end_times_provided()
36
- if config[:start_time] && !config[:end_time]
37
- ui.error("The start_time option was provided, but the end_time option was not. If one is provided, the other is required.")
38
- exit 1
39
- elsif config[:end_time] && !config[:start_time]
40
- ui.error("The end_time option was provided, but the start_time option was not. If one is provided, the other is required.")
41
- exit 1
42
- end
43
- end
44
-
45
- def convert_to_unix_timestamps()
46
- if config[:unix_timestamps]
47
- start_time = config[:start_time].to_i
48
- end_time = config[:end_time].to_i
49
- else
50
- # Take user supplied input, assumes it is in a valid date format,
51
- # convert to a date object to ensure we have the proper date format for
52
- # passing to the time object (but converting is not a validation step,
53
- # so bad user input will still be bad)
54
- # then convert to a time object, and then convert to a unix timestamp
55
- # An error could potentially be thrown if the conversions don't work
56
- # This does work on windows - to_i on time even on windows still returns a unix timestamp
57
- # Verified on ruby 1.9.3 on a windows 2000 ami on aws
58
- start_time = Time.parse(Date.strptime(config[:start_time], '%m-%d-%Y').to_s).to_i
59
- end_time = Time.parse(Date.strptime(config[:end_time], '%m-%d-%Y').to_s).to_i
60
- end
61
-
62
- return start_time, end_time
63
- end
64
-
65
- def check_3month_window(start_time, end_time)
66
- # start_time and end_time are unix timestamps
67
- if (end_time - start_time) > SECONDS_IN_3MONTHS
68
- ui.error("Requesting information for more than three months at a time is disallowed. Please try a smaller timeframe.")
69
- exit 1
70
- end
71
- end
72
-
73
- end