Grid環境構築用のChefリポジトリです。
Revision | 804bdd4000547ac18a0fcb504b201c8eafb74b25 (tree) |
---|---|
Time | 2016-12-10 12:27:59 |
Author | whitestar <whitestar@gaea...> |
Commiter | whitestar |
platform_utils-0.1.1
@@ -1,6 +1,10 @@ | ||
1 | 1 | platform_utils CHANGELOG |
2 | 2 | ======================== |
3 | 3 | |
4 | +0.1.1 | |
5 | +----- | |
6 | +- improves update command string validation. | |
7 | + | |
4 | 8 | 0.1.0 |
5 | 9 | ----- |
6 | 10 | - Initial release of platform_utils |
\ No newline at end of file |
@@ -10,6 +10,7 @@ This cookbook provides platform utility recipes. | ||
10 | 10 | - [Packages](#packages) |
11 | 11 | - [Cookbooks](#cookbooks) |
12 | 12 | - [Attributes](#attributes) |
13 | +- [Usage](#usage) | |
13 | 14 | - [Recipes](#recipes) |
14 | 15 | - [platform_utils::default](#platform_utilsdefault) |
15 | 16 | - [platform_utils::platform_update](#platform_utilsplatform_update) |
@@ -35,6 +36,8 @@ This cookbook provides platform utility recipes. | ||
35 | 36 | |`['platform_utils']['platform_update']['apt-get']['command']`|String|apt-get upgrade/dist-upgrade command string.|`'apt-get upgrade -y'`| |
36 | 37 | |`['platform_utils']['platform_update']['yum']['command']`|String|yum update command string.|`'yum update -y'`| |
37 | 38 | |
39 | +## Usage | |
40 | + | |
38 | 41 | ### Recipes |
39 | 42 | |
40 | 43 | #### platform_utils::default |
@@ -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 |
@@ -5,7 +5,7 @@ maintainer_email '' | ||
5 | 5 | license 'Apache 2.0' |
6 | 6 | description 'Platform Utilities' |
7 | 7 | long_description IO.read(File.join(File.dirname(__FILE__), 'README.md')) |
8 | -version '0.1.0' | |
8 | +version '0.1.1' | |
9 | 9 | source_url 'http://scm.osdn.jp/gitroot/metasearch/grid-chef-repo.git' |
10 | 10 | issues_url 'https://osdn.jp/projects/metasearch/ticket' |
11 | 11 |
@@ -19,15 +19,18 @@ | ||
19 | 19 | |
20 | 20 | require 'shellwords' |
21 | 21 | |
22 | +::Chef::Recipe.send(:include, PlatformUtils::Helper) | |
23 | + | |
22 | 24 | if node['platform_utils']['platform_update']['auto_update'] |
23 | 25 | case node['platform_family'] |
24 | 26 | when 'debian' then |
25 | 27 | 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' | |
28 | 30 | Chef::Log.fatal('You must use apt-get command.') |
29 | 31 | raise |
30 | 32 | end |
33 | + validate_shellwords(words) | |
31 | 34 | |
32 | 35 | execute 'apt-get_upgrade' do |
33 | 36 | user 'root' |
@@ -36,11 +39,12 @@ if node['platform_utils']['platform_update']['auto_update'] | ||
36 | 39 | end |
37 | 40 | when 'rhel' then |
38 | 41 | 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' | |
41 | 44 | Chef::Log.fatal('You must use yum command.') |
42 | 45 | raise |
43 | 46 | end |
47 | + validate_shellwords(words) | |
44 | 48 | |
45 | 49 | execute 'yum_update' do |
46 | 50 | user 'root' |