• R/O
  • HTTP
  • SSH
  • HTTPS

grid-chef-repo: Commit

Grid環境構築用のChefリポジトリです。


Commit MetaInfo

Revision804bdd4000547ac18a0fcb504b201c8eafb74b25 (tree)
Time2016-12-10 12:27:59
Authorwhitestar <whitestar@gaea...>
Commiterwhitestar

Log Message

platform_utils-0.1.1

Change Summary

Incremental Difference

--- a/cookbooks/platform_utils/CHANGELOG.md
+++ b/cookbooks/platform_utils/CHANGELOG.md
@@ -1,6 +1,10 @@
11 platform_utils CHANGELOG
22 ========================
33
4+0.1.1
5+-----
6+- improves update command string validation.
7+
48 0.1.0
59 -----
610 - Initial release of platform_utils
\ No newline at end of file
--- a/cookbooks/platform_utils/README.md
+++ b/cookbooks/platform_utils/README.md
@@ -10,6 +10,7 @@ This cookbook provides platform utility recipes.
1010 - [Packages](#packages)
1111 - [Cookbooks](#cookbooks)
1212 - [Attributes](#attributes)
13+- [Usage](#usage)
1314 - [Recipes](#recipes)
1415 - [platform_utils::default](#platform_utilsdefault)
1516 - [platform_utils::platform_update](#platform_utilsplatform_update)
@@ -35,6 +36,8 @@ This cookbook provides platform utility recipes.
3536 |`['platform_utils']['platform_update']['apt-get']['command']`|String|apt-get upgrade/dist-upgrade command string.|`'apt-get upgrade -y'`|
3637 |`['platform_utils']['platform_update']['yum']['command']`|String|yum update command string.|`'yum update -y'`|
3738
39+## Usage
40+
3841 ### Recipes
3942
4043 #### platform_utils::default
--- /dev/null
+++ b/cookbooks/platform_utils/libraries/helper.rb
@@ -0,0 +1,35 @@
1+#
2+# Cookbook Name:: platform_utils
3+# Library:: Helper
4+#
5+# Copyright 2016, whitestar
6+#
7+# Licensed under the Apache License, Version 2.0 (the "License");
8+# you may not use this file except in compliance with the License.
9+# You may obtain a copy of the License at
10+#
11+# http://www.apache.org/licenses/LICENSE-2.0
12+#
13+# Unless required by applicable law or agreed to in writing, software
14+# distributed under the License is distributed on an "AS IS" BASIS,
15+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+# See the License for the specific language governing permissions and
17+# limitations under the License.
18+#
19+
20+require 'shellwords'
21+
22+module PlatformUtils
23+ # Helper methods
24+ module Helper
25+ def validate_shellwords(words)
26+ invalid_word = words.find {|word|
27+ word =~ /[;\|&<>`]/
28+ }
29+ unless invalid_word.nil?
30+ Chef::Log.fatal("Command string includes the invalid character (;|&<>`): #{invalid_word}")
31+ raise
32+ end
33+ end
34+ end
35+end
--- a/cookbooks/platform_utils/metadata.rb
+++ b/cookbooks/platform_utils/metadata.rb
@@ -5,7 +5,7 @@ maintainer_email ''
55 license 'Apache 2.0'
66 description 'Platform Utilities'
77 long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
8-version '0.1.0'
8+version '0.1.1'
99 source_url 'http://scm.osdn.jp/gitroot/metasearch/grid-chef-repo.git'
1010 issues_url 'https://osdn.jp/projects/metasearch/ticket'
1111
--- a/cookbooks/platform_utils/recipes/platform_update.rb
+++ b/cookbooks/platform_utils/recipes/platform_update.rb
@@ -19,15 +19,18 @@
1919
2020 require 'shellwords'
2121
22+::Chef::Recipe.send(:include, PlatformUtils::Helper)
23+
2224 if node['platform_utils']['platform_update']['auto_update']
2325 case node['platform_family']
2426 when 'debian' then
2527 update_command = node['platform_utils']['platform_update']['apt-get']['command']
26- shellwords = Shellwords.split(update_command)
27- unless shellwords[0] == 'apt-get'
28+ words = Shellwords.split(update_command)
29+ unless words[0] == 'apt-get'
2830 Chef::Log.fatal('You must use apt-get command.')
2931 raise
3032 end
33+ validate_shellwords(words)
3134
3235 execute 'apt-get_upgrade' do
3336 user 'root'
@@ -36,11 +39,12 @@ if node['platform_utils']['platform_update']['auto_update']
3639 end
3740 when 'rhel' then
3841 update_command = node['platform_utils']['platform_update']['yum']['command']
39- shellwords = Shellwords.split(update_command)
40- unless shellwords[0] == 'yum'
42+ words = Shellwords.split(update_command)
43+ unless words[0] == 'yum'
4144 Chef::Log.fatal('You must use yum command.')
4245 raise
4346 end
47+ validate_shellwords(words)
4448
4549 execute 'yum_update' do
4650 user 'root'
Show on old repository browser