csm-resource-generator 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 986689b611b54edde9e5d02a72ea141d1f5f998d
4
+ data.tar.gz: f244e6982ff6e89aa78532f62c7d9d5d35894b47
5
+ SHA512:
6
+ metadata.gz: 0bb72afb2b292c8e0c85c982e09aa63859b2ebe735707d47c81d9572135150b0fd31dac423be1e8378927c8412ec59f66a2af4a8610125e451c93a610e43dead
7
+ data.tar.gz: 84b41f83bcc039c1f067ba88bbdfabf46a6aafd5e29c065d14a0c938ca68b13dce06865fdbc731de0ddd4ca3f00cbf132148e6b3d4429900c50f827b716c70b8
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *~
11
+ /vendor/bundle
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.3.1
5
+ before_install: gem install bundler -v 1.12.5
@@ -0,0 +1,49 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer at tamura.masahiro@jp.fujitsu.com. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [homepage]: http://contributor-covenant.org
49
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in csm-resource-generator.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Masahiro TAMURA
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,38 @@
1
+ # Csm::Resource::Generator
2
+
3
+ A XML Generator for [CSM](http://www.fujitsu.com/jp/products/software/middleware/business-middleware/middleware/csm/) version 1.1 or later.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'csm-resource-generator'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install csm-resource-generator
20
+
21
+ ## Usage
22
+
23
+ ### create XML files for `fscsm_org create`
24
+
25
+ ```
26
+ bundle exec csm-resource-generator org orgSample 2:3:3 output.xml
27
+ ```
28
+
29
+
30
+ ## Contributing
31
+
32
+ Bug reports and pull requests are welcome on GitHub at https://github.com/tamoot/csm-resource-generator. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
33
+
34
+
35
+ ## License
36
+
37
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
38
+
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ end
9
+
10
+ task :default => :test
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "csm/resource/generator"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'csm/resource/generator/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "csm-resource-generator"
8
+ spec.version = Csm::Resource::Generator::VERSION
9
+ spec.authors = ["Masahiro TAMURA"]
10
+ spec.email = ["tamoot@gmail.com"]
11
+
12
+ spec.summary = %q{Resource Generator for CSM}
13
+ spec.description = %q{Resource Generator for Cloud Services Managements. http://jp.fujitsu.com/solutions/cloud/paas/services-management/}
14
+ spec.homepage = "https://github.com/tamoot/csm-resource-generator"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ spec.bindir = "exe"
19
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
20
+ spec.require_paths = ["lib"]
21
+
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ spec.add_development_dependency "minitest", "~> 5.0"
25
+ spec.add_dependency 'thor', '~> 0.18'
26
+ end
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "csm/resource/generator"
4
+ Csm::Resource::Generator::Command.start
@@ -0,0 +1,27 @@
1
+ require "thor"
2
+ require "csm/resource/generator/version"
3
+ require "csm/resource/generator/org"
4
+
5
+ class Thor
6
+ module Shell
7
+ class Basic
8
+ def print_wrapped(message, options = {})
9
+ stdout.puts message
10
+ end
11
+ end
12
+ end
13
+ end
14
+
15
+ module Csm
16
+ module Resource
17
+ module Generator
18
+ class Command < ::Thor
19
+ desc Csm::Resource::Generator::Org::desc_first, Csm::Resource::Generator::Org::desc_second
20
+ long_desc Csm::Resource::Generator::Org::long_desc
21
+ def org(prefix, information, output)
22
+ Csm::Resource::Generator::Org.new.run(prefix, information, output)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,14 @@
1
+ <org>
2
+ <orgId><%= org_id %></orgId>
3
+ <orgAbbreviation><%= org_abb %></orgAbbreviation>
4
+ <orgName><%= org_name%></orgName>
5
+ <parentOrgId><%= parent_org_id %></parentOrgId>
6
+ <comment><%= comment %></comment>
7
+ <customFields>
8
+ <customField no="1"></customField>
9
+ <customField no="2"></customField>
10
+ <customField no="3"></customField>
11
+ <customField no="4"></customField>
12
+ <customField no="5"></customField>
13
+ </customFields>
14
+ </org>
@@ -0,0 +1,46 @@
1
+ # coding: utf-8
2
+
3
+ require 'erb'
4
+
5
+ class OrgCreate
6
+ @@erb = File::read(File::expand_path("../../erb/org.xml.erb", __FILE__), :encoding => 'UTF-8')
7
+
8
+ attr_accessor :prefix, :rank, :org_id, :parent_org_id, :comment
9
+
10
+ def self.rank_array=(r)
11
+ @@rank_array = r
12
+ end
13
+
14
+ def self.rank_array
15
+ @@rank_array
16
+ end
17
+
18
+ def org_abb
19
+ "略称-#{org_id}"
20
+ end
21
+
22
+ def org_name
23
+ "組織-#{org_id}"
24
+ end
25
+
26
+ def to_xml
27
+ ERB.new(@@erb, nil, '-').result(binding)
28
+ end
29
+
30
+ def generate_children_recursive(data)
31
+
32
+ childern_num = @@rank_array[self.rank + 1].nil? ? 0 : @@rank_array[self.rank + 1] - 1
33
+ return if childern_num <= 0
34
+
35
+ 0.upto(@@rank_array[self.rank + 1] - 1) do |i|
36
+ o = OrgCreate.new
37
+ o.org_id = "#{self.org_id}-#{"%03d" % i}"
38
+ o.parent_org_id = self.org_id
39
+ o.rank = self.rank + 1
40
+ o.comment = "#{self.comment}/#{o.org_id}"
41
+ data << o
42
+
43
+ o.generate_children_recursive(data)
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,88 @@
1
+ require "csm/resource/generator/model/org_create"
2
+ require "pp"
3
+
4
+ module Csm::Resource::Generator
5
+ class Org
6
+
7
+ def self.desc_first
8
+ 'org [prefix] [information] [output file]'
9
+ end
10
+
11
+ def self.desc_second
12
+ 'Create xml files for `fscsm_org create`'
13
+ end
14
+
15
+ def initialize
16
+ end
17
+
18
+ def create_top_rank(org_id)
19
+ o = OrgCreate.new
20
+ o.org_id = org_id
21
+ o.parent_org_id = "!root"
22
+ o.rank = 0
23
+ o.comment = "/#{org_id}"
24
+ o
25
+ end
26
+
27
+ def run(prefix, information, output)
28
+ xml_file = File::join(Dir::pwd, output)
29
+ STDOUT.puts "Outputs the specified file:`#{xml_file}`.\nIs it ok? [Yn]"
30
+ typed = STDIN.gets
31
+ exit if typed.upcase == "N"
32
+
33
+ data = []
34
+ begin
35
+
36
+ OrgCreate.rank_array = information.split(":").map{|s|s.to_i}
37
+
38
+ 0.upto(OrgCreate::rank_array[0].to_i - 1) do |i|
39
+ o = create_top_rank("#{prefix}-#{"%03d" % i}")
40
+ data << o
41
+
42
+ o.generate_children_recursive(data)
43
+
44
+ end
45
+
46
+ data.sort! do |d1, d2|
47
+ (d1.rank <=> d2.rank).nonzero? || (d1.org_id <=> d2.org_id)
48
+ end
49
+
50
+ File::open(xml_file, 'w') do |xml|
51
+ xml.puts %|<?xml version="1.0" encoding="UTF-8"?>|
52
+ xml.puts %|<orgs>|
53
+ data.each do |d|
54
+ xml.puts d.to_xml
55
+ end
56
+ xml.puts %|</orgs>|
57
+ end
58
+
59
+ STDOUT.puts "Output done."
60
+
61
+ rescue
62
+ STDERR.puts $!
63
+ STDERR.puts $!.backtrace.join("\n")
64
+
65
+ end
66
+
67
+ end
68
+
69
+ def self.long_desc
70
+ a = <<~USAGE
71
+ Outputs the XML that contains a hierarchical organization data for `fscsm_org import`
72
+ [sample args]
73
+ org orgSample 1:3:3
74
+ -> orgSample000/orgSample000-000/orgSample000-000-000
75
+ /orgSample000-000-001
76
+ /orgSample000-000-002
77
+ /orgSample000-001/orgSample000-001-000
78
+ /orgSample000-001-001
79
+ /orgSample000-001-002
80
+ /orgSample000-002/orgSample000-002-000
81
+ /orgSample000-002-001
82
+ /orgSample000-002-002
83
+
84
+ USAGE
85
+ a.split("\n").map{|s| " #{s}"}.join("\n")
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,7 @@
1
+ module Csm
2
+ module Resource
3
+ module Generator
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: csm-resource-generator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Masahiro TAMURA
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-09-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.12'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.12'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: thor
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '0.18'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '0.18'
69
+ description: Resource Generator for Cloud Services Managements. http://jp.fujitsu.com/solutions/cloud/paas/services-management/
70
+ email:
71
+ - tamoot@gmail.com
72
+ executables:
73
+ - csm-resource-generator
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".travis.yml"
79
+ - CODE_OF_CONDUCT.md
80
+ - Gemfile
81
+ - LICENSE.txt
82
+ - README.md
83
+ - Rakefile
84
+ - bin/console
85
+ - bin/setup
86
+ - csm-resource-generator.gemspec
87
+ - exe/csm-resource-generator
88
+ - lib/csm/resource/generator.rb
89
+ - lib/csm/resource/generator/erb/org.xml.erb
90
+ - lib/csm/resource/generator/model/org_create.rb
91
+ - lib/csm/resource/generator/org.rb
92
+ - lib/csm/resource/generator/version.rb
93
+ homepage: https://github.com/tamoot/csm-resource-generator
94
+ licenses:
95
+ - MIT
96
+ metadata: {}
97
+ post_install_message:
98
+ rdoc_options: []
99
+ require_paths:
100
+ - lib
101
+ required_ruby_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ required_rubygems_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ requirements: []
112
+ rubyforge_project:
113
+ rubygems_version: 2.5.1
114
+ signing_key:
115
+ specification_version: 4
116
+ summary: Resource Generator for CSM
117
+ test_files: []