sct 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 762ae0c4c6894b093725f8743e0ca0b639d28bd2d88a572a04817a704e1d1613
4
+ data.tar.gz: ed0c32930792fcc5471c6e74e0a5cd79b9635fb2a4c0612217357f2e3ceabe6a
5
+ SHA512:
6
+ metadata.gz: 4dc5aff3e3eb2879a5921e5303f0bb9887ba11c7dc0a77d6d58ebc620d5aa478543a6f9a177a536ef4626e8011f5f670c062e6dfb06cdbb23d077c2b5f5e9bbe
7
+ data.tar.gz: 5d1f86be5ded9b2171ecb52ff52d2a4390825cd5f1b746a73376a7f6c3af142edb5dc88cd11361ade50202b531a242418063427e909546b77920d56f1ebaeef4
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.6.2
7
+ before_install: gem install bundler -v 2.0.2
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at reshad@proactive.nl. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in sct.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,47 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sct (0.1.0)
5
+ class_interface
6
+ colored (~> 1.2)
7
+ commander (~> 4.4.7)
8
+ hosts (~> 0.1.1)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ class_interface (0.1.1)
14
+ colored (1.2)
15
+ commander (4.4.7)
16
+ highline (~> 2.0.0)
17
+ diff-lcs (1.3)
18
+ highline (2.0.3)
19
+ hosts (0.1.1)
20
+ linebreak (~> 2.0.1)
21
+ linebreak (2.0.1)
22
+ rake (10.5.0)
23
+ rspec (3.9.0)
24
+ rspec-core (~> 3.9.0)
25
+ rspec-expectations (~> 3.9.0)
26
+ rspec-mocks (~> 3.9.0)
27
+ rspec-core (3.9.1)
28
+ rspec-support (~> 3.9.1)
29
+ rspec-expectations (3.9.0)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.9.0)
32
+ rspec-mocks (3.9.1)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.9.0)
35
+ rspec-support (3.9.2)
36
+
37
+ PLATFORMS
38
+ ruby
39
+
40
+ DEPENDENCIES
41
+ bundler (~> 2.0)
42
+ rake (~> 10.0)
43
+ rspec (~> 3.0)
44
+ sct!
45
+
46
+ BUNDLED WITH
47
+ 2.0.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Reshad Farid
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.
data/README.md ADDED
@@ -0,0 +1,112 @@
1
+ # SCT
2
+ The **SCT** command line tool helps developers set up and maintain a Kubernetes (k8s) cluster on their development machine which closely resembles the production setup.
3
+
4
+ The tool is geared towards the implementation of a local development environment in compliance with the [*Visma Cloud Delivery Model*](https://www.visma.com/blog/our-large-scale-devops-transformation/) (SCT) to be deployed on *Google Cloud Services*.
5
+
6
+ The SCT tool is a collection of commands that can be run from your local development environment. These commands will take care of some steps necessary to initialize the development environment, but also of some recurring tasks to keep this environment going on a daily base.
7
+
8
+ This README will provide an installation guide, an overview of the available commands and a brief guide for developers that need to contribute to the **SCT** CLI tool.
9
+
10
+ The tool is written in Ruby and is meant to run on *Windows, Linux and Mac* environments.
11
+
12
+ ## Installation
13
+
14
+ 1) Open a terminal or bash window and make sure [**Ruby**](https://www.ruby-lang.org/en/documentation/installation/) is installed on your machine with _version >= 2.6.*_
15
+
16
+ $ which ruby
17
+ $ ruby --version
18
+
19
+ 2) As this Ruby Gem is not yet published, you will need to install the *SCT* tool from this repository and use Ruby [**bundler**](https://bundler.io/) to manage dependencies.
20
+
21
+ $ gem install bundler
22
+
23
+ 3) Navigate to a (new) folder where you want the SCT code, and clone this repository:
24
+
25
+ $ git clone https://github.com/reshadf/sct.git
26
+
27
+ 4) Then let **bundler** manage the dependencies:
28
+
29
+ $ bundle
30
+
31
+ 5) And let **gem** create a binary:
32
+
33
+ $ gem install sct
34
+
35
+ 6) Now, the **sct** tool is available anywhere from the command line
36
+
37
+ $ sct --help
38
+
39
+
40
+ ## Usage
41
+
42
+ SCT offers a number of commands to help developers set up a local development environment for Visma Cloud To get an overview of what **sct** can do, run
43
+
44
+ $ sct --help
45
+
46
+ To initialize a **sct** configuration file
47
+
48
+ $ sct init
49
+
50
+ To patch the hostfile with the local IP of the k8s cluster:
51
+
52
+ $ sct hostfile
53
+
54
+ To add the secret for the MySQL proxy:
55
+
56
+ $ sct mysql_proxy
57
+
58
+
59
+ ## Development
60
+
61
+ For development of the **sct** tool, the installation needs to be a bit different.
62
+
63
+ Repeat steps 1-3 from the installation instruction above.
64
+
65
+ 4) We will use [**rake**](https://github.com/ruby/rake) as a Ruby develoment tool for running tests and generating binaries:
66
+
67
+ $ gem install rake
68
+
69
+ 5) Use the setup script from the repo to install dependencies:
70
+
71
+ $ bin/setup
72
+
73
+ 5) Do tests to make sure everything works fine before you start:
74
+
75
+ $ rake spec
76
+
77
+ 6) Install dependency gems:
78
+
79
+ $ bundle exec rake install
80
+
81
+ 7) Your development environment is now ready. After you have made edits to the code, you can generate a new binary to test the code like this:
82
+
83
+ $ rake install
84
+
85
+ 8) You can then run the binary directly from the command line:
86
+
87
+ $ sct --help
88
+
89
+ ### Development tips
90
+
91
+ - To release a new version, update the version number in `version.rb`, and then run:
92
+
93
+ $ bundle exec rake release
94
+
95
+ This will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
96
+
97
+ ### Adding commands
98
+
99
+ Adding a new command is as simple as adding a new 'Command' Class to the *lib/sct/commands* folder. As long as you implement the constants and methods of *lib/sct/command_interface.rb*, your new Command will automatically appear in the CLI Help and can be called. Use the *lib/sct/command_option.rb* to define command options. Examples of Command Classes can be found inside the *lib/sct/commands* folder.
100
+
101
+
102
+ ## Contributing
103
+
104
+ Bug reports and pull requests are welcome on GitHub at https://gitlab.com/proactive-software/packages/sct. 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.
105
+
106
+ ## License
107
+
108
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
109
+
110
+ ## Code of Conduct
111
+
112
+ Everyone interacting in the Sct project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://gitlab.com/proactive-software/packages/sct/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "sct"
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(__FILE__)
data/bin/sct ADDED
@@ -0,0 +1,23 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'commander/import'
4
+ require 'sct'
5
+
6
+ if RUBY_VERSION < '2.0.0'
7
+ abort("Sct requires Ruby 2.0.0 or higher")
8
+ end
9
+
10
+ def self.windows?
11
+ (/cygwin|mswin|mingw|bccwin|wince|emx/ =~ RUBY_PLATFORM) != nil
12
+ end
13
+
14
+ if ARGV.include?('-v') || ARGV.include?('--version')
15
+ # This will print out the Sct binary path right above the
16
+ # version number. Very often, users are not aware they have
17
+ # e.g. bundled Sct installed
18
+ puts("Sct installation at path:")
19
+ puts(File.expand_path(__FILE__))
20
+ puts("-----------------------------")
21
+ end
22
+
23
+ Sct::SctCore.take_off(Sct.constants.map(&Sct.method(:const_get)).grep(Class))
data/bin/setup ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
data/lib/.DS_Store ADDED
Binary file
data/lib/sct.rb ADDED
@@ -0,0 +1,55 @@
1
+ require "sct/version"
2
+ require "colored"
3
+
4
+ module Sct
5
+ class Error < StandardError; end
6
+
7
+ class SctCore
8
+
9
+ def self.take_off(cmds)
10
+ program :name, 'Sct'
11
+ program :version, Sct::VERSION
12
+ program :summary, 'CLI helper tool for local Sct development'
13
+ program :description, 'Sct is a CLI tool for developers using the Visma Continuous Deployment Model in conjunction with the Google Cloud Platform (GCP). It provides multiple command to set up and maintain a kubernetes cluster on a machine for local development'
14
+
15
+ cmds.each { |cmd| registerCommand(cmd) }
16
+ end
17
+
18
+ def self.registerCommand(cmd)
19
+ # validate Command Class
20
+ if cmd.class != Class ||
21
+ !cmd.name.end_with?('Command')
22
+ return
23
+ end
24
+
25
+ # validate if Command is meant to be public
26
+ if !cmd::IS_PUBLIC_COMMAND
27
+ return
28
+ end
29
+
30
+ # register public Commands as CLI command
31
+ command self.deduceCommandNameFromClass(cmd) do |c|
32
+ c.syntax = cmd::SYNTAX
33
+ c.summary = cmd::SUMMARY
34
+ c.description = cmd::DESCRIPTION
35
+ c.example cmd::EXAMPLE_DESCRIPTION, cmd::EXAMPLE
36
+ cmd::OPTIONS.each { |option| c.option option.name, option.type, option.description }
37
+ c.action do |args, options|
38
+ cmd.new.execute(args, options)
39
+ end
40
+ end
41
+ end
42
+
43
+ # retrieves cli command-name from Command's full Class name
44
+ def self.deduceCommandNameFromClass(c)
45
+ name = c.name
46
+ if name.include?('::')
47
+ name = name.partition('::')[2]
48
+ end
49
+ # TODO replace camel-case capitals with '-'
50
+ return name.chomp('Command').downcase
51
+ end
52
+
53
+ end
54
+
55
+ end
data/lib/sct/.DS_Store ADDED
Binary file
@@ -0,0 +1,6 @@
1
+ module Sct
2
+
3
+ project_root = File.dirname(File.absolute_path(__FILE__))
4
+ Dir.glob(project_root + '/commands/*', &method(:require))
5
+
6
+ end
@@ -0,0 +1,18 @@
1
+ require 'class_interface'
2
+
3
+ class CommandInterface
4
+ IS_PUBLIC_COMMAND = true | false
5
+ SYNTAX = String
6
+ SUMMARY = String
7
+ DESCRIPTION = String
8
+ EXAMPLE = String
9
+ EXAMPLE_DESCRIPTION = String
10
+ OPTIONS = Array
11
+
12
+ def initialize
13
+ end
14
+
15
+ def execute(args, options)
16
+ end
17
+
18
+ end
@@ -0,0 +1,14 @@
1
+ module Sct
2
+
3
+ class CommandOption
4
+ attr_reader :name, :type, :description
5
+
6
+ def initialize(name, type, description)
7
+ @name = name
8
+ @type = type
9
+ @description = description
10
+ end
11
+
12
+ end
13
+
14
+ end
@@ -0,0 +1,129 @@
1
+ require 'sct/command_interface'
2
+
3
+ module Sct
4
+ class HostfileCommand
5
+
6
+ IS_PUBLIC_COMMAND = true
7
+ SYNTAX = 'sct hostfile'
8
+ SUMMARY = 'adds the ingress url to the users hostfile'
9
+ DESCRIPTION = ""
10
+ EXAMPLE = "sct hostfile --path=/mnt/c/Windows/System32/drivers/etc/hosts"
11
+ EXAMPLE_DESCRIPTION = ""
12
+
13
+ OPTIONS = []
14
+
15
+ def initialize
16
+ end
17
+
18
+ def self.options
19
+ end
20
+
21
+ def execute(args, options)
22
+
23
+ require 'hosts'
24
+
25
+ return unless ingressUrl
26
+ url = ingressUrl
27
+
28
+ if !options.path.nil?
29
+ hosts = Hosts::File.read(options.path)
30
+ elsif setup && sct_file["hostpath"]
31
+ hosts = Hosts::File.read("#{sct_file["hostpath"]}")
32
+ else
33
+ puts "No hostpath found in Sctfile using default /etc/hosts".yellow
34
+ hosts = Hosts::File.read('/etc/hosts')
35
+ end
36
+
37
+ if ([url].any? { |ip| hosts.to_s =~ /#{ip}/ })
38
+ puts "Already exist and skipped.".green
39
+ else
40
+ validate_if_exist(hosts)
41
+ add_entry(url, hosts)
42
+ hosts.write
43
+ puts "patched: #{url}".green
44
+ end
45
+
46
+ end
47
+
48
+ def add_entry(url, hosts)
49
+ spend = Hosts::Entry.new(
50
+ url,
51
+ 'spend.cloud.local',
52
+ :comment => 'The spend cloud ingress url'
53
+ )
54
+
55
+ mail = Hosts::Entry.new(
56
+ url,
57
+ 'mail.spend.cloud.local',
58
+ :comment => 'The spend cloud mail url'
59
+ )
60
+
61
+ config = Hosts::Entry.new(
62
+ url,
63
+ 'config.spend.cloud.local',
64
+ :comment => 'The spend cloud config url'
65
+ )
66
+
67
+ spend_cloud = Hosts::Entry.new(
68
+ url,
69
+ 'spend-cloud.spend.cloud.local',
70
+ :comment => 'The spend cloud web app url'
71
+ )
72
+
73
+ docs = Hosts::Entry.new(
74
+ url,
75
+ 'docs.spend.cloud.local',
76
+ :comment => 'The spend cloud documentation url'
77
+ )
78
+
79
+ hosts.elements << spend
80
+ hosts.elements << mail
81
+ hosts.elements << config
82
+ hosts.elements << spend_cloud
83
+ hosts.elements << docs
84
+
85
+ end
86
+
87
+ def validate_if_exist(array)
88
+ rejectArray = Array.new
89
+
90
+ array.to_s.each_line.with_index do |line, index|
91
+
92
+ if (line =~ /(?:spend\.cloud\.local)./)
93
+ rejectArray.push(index)
94
+ end
95
+
96
+ end
97
+
98
+ array.elements.delete_if.each_with_index { |value, index| rejectArray.include? index }
99
+
100
+ end
101
+
102
+ def ingressUrl
103
+ return Sct::Helpers.ingressUrl
104
+ end
105
+
106
+ def setup
107
+
108
+ return false unless Sct::SctFolder.setup?
109
+
110
+ return true
111
+
112
+ end
113
+
114
+ def sct_file
115
+
116
+ return unless setup
117
+
118
+ sct_file_string = File.read(Sct::SctFolder.sctfile_path)
119
+
120
+ sct_file_hash = Sct::Helpers.to_hash(sct_file_string)
121
+
122
+ return sct_file_hash
123
+ end
124
+
125
+ implements CommandInterface
126
+
127
+ end
128
+
129
+ end
@@ -0,0 +1,29 @@
1
+ require 'Sct/command_interface'
2
+
3
+ module Sct
4
+
5
+ class InitCommand
6
+
7
+ IS_PUBLIC_COMMAND = true
8
+ SYNTAX = 'Sct init'
9
+ SUMMARY = 'Initialize a base configuration file for Sct'
10
+ EXAMPLE = 'Sct init'
11
+ EXAMPLE_DESCRIPTION = 'Sct init will create a Sct folder inside your working directory and a Sctfile'
12
+ DESCRIPTION = "Sct init will create a configuration file called Sctfile in your project"
13
+
14
+ OPTIONS = []
15
+
16
+ def initialize
17
+
18
+ end
19
+
20
+ def execute(args, options)
21
+ require "Sct/setup/setup"
22
+ Sct::Setup.start
23
+ end
24
+
25
+ implements CommandInterface
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,72 @@
1
+ require 'sct/command_interface'
2
+ require 'sct/command_option'
3
+ require "sct/sct_folder"
4
+ require "sct/setup/helpers"
5
+
6
+ module Sct
7
+
8
+ class Mysql_proxyCommand
9
+
10
+
11
+ DEFAULT_SECRET_NAME = "gcloud-credentials"
12
+
13
+ IS_PUBLIC_COMMAND = true
14
+ SYNTAX = 'sct mysql_proxy'
15
+ SUMMARY = 'adds a secret for the mysql proxy'
16
+ DESCRIPTION = ""
17
+ EXAMPLE = ""
18
+ EXAMPLE_DESCRIPTION = ""
19
+
20
+ OPTIONS = []
21
+
22
+ @path
23
+ @secret_name
24
+
25
+ def initialize
26
+
27
+ return unless setup
28
+
29
+ @path = sct_file["cloud-proxy-path"]
30
+ @secret_name = DEFAULT_SECRET_NAME
31
+ end
32
+
33
+ def self.options
34
+
35
+ end
36
+
37
+ def execute(args, options)
38
+
39
+ return puts "No sct directory found".red unless setup
40
+
41
+ system("kubectl delete secret gcloud-credentials")
42
+ system("kubectl create secret generic gcloud-credentials --from-file=#{@path}")
43
+
44
+ puts "Authenticated with secret-name: '#{@secret_name}'".green
45
+
46
+ return true
47
+ end
48
+
49
+ def setup
50
+
51
+ return false unless Sct::SctFolder.setup?
52
+
53
+ return true
54
+
55
+ end
56
+
57
+ def sct_file
58
+
59
+ return unless setup
60
+
61
+ sct_file_string = File.read(Sct::SctFolder.sctfile_path)
62
+
63
+ sct_file_hash = Sct::Helpers.to_hash(sct_file_string)
64
+
65
+ return sct_file_hash
66
+ end
67
+
68
+ implements CommandInterface
69
+
70
+ end
71
+
72
+ end
@@ -0,0 +1,4 @@
1
+ module Sct
2
+ # parameter names
3
+ PAR_SECRET_NAME = "secret-name"
4
+ end
@@ -0,0 +1,35 @@
1
+ module Sct
2
+ class SctFolder
3
+ FOLDER_NAME = "Sct"
4
+
5
+ def self.path
6
+ value ||= "./#{FOLDER_NAME}/" if File.directory?("./#{FOLDER_NAME}/")
7
+ value ||= "./.#{FOLDER_NAME}/" if File.directory?("./.#{FOLDER_NAME}/") # hidden folder
8
+ value ||= "./" if File.basename(Dir.getwd) == FOLDER_NAME && File.exist?('Sctfile') # inside the folder
9
+ value ||= "./" if File.basename(Dir.getwd) == ".#{FOLDER_NAME}" && File.exist?('Sctfile') # inside the folder and hidden
10
+ return value
11
+ end
12
+
13
+ def self.Sctfile_path
14
+ return nil if self.path.nil?
15
+
16
+ path = File.join(self.path, 'Sctfile')
17
+ return path if File.exist?(path)
18
+ return nil
19
+ end
20
+
21
+ # Does a Sct configuration already exist?
22
+ def self.setup?
23
+ return false unless self.Sctfile_path
24
+ File.exist?(self.Sctfile_path)
25
+ end
26
+
27
+ def self.create_folder!(path = nil)
28
+ path = File.join(path || '.', FOLDER_NAME)
29
+ return if File.directory?(path) # directory is already there
30
+ puts "Found a folder called 'Sct' at path '#{path}', please delete it" if File.exist?(path)
31
+ FileUtils.mkdir_p(path)
32
+ puts "Created new folder '#{path}'."
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,22 @@
1
+ module Vcdm
2
+ class Helpers
3
+
4
+ def self.ingressUrl
5
+ ip = `kubectl get ingress`
6
+
7
+ if ip.nil? || ip.empty?
8
+ puts "Can't fetch ip from kubectl".yellow
9
+ return nil
10
+ end
11
+
12
+ match = ip.scan(/((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)(\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)){3})/);
13
+ return match[0].first
14
+ end
15
+
16
+ def self.to_hash(str)
17
+ Hash[
18
+ str.split("\n").map{|i|i.split('=')}
19
+ ]
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,37 @@
1
+ module Sct
2
+ class Setup
3
+
4
+ attr_accessor :Sctfile_content
5
+
6
+ def self.start
7
+
8
+ require "Sct/Sct_folder"
9
+
10
+ if Sct::SctFolder.setup?
11
+ puts "Already setup at path `#{Sct::SctFolder.path}`"
12
+ return
13
+ end
14
+
15
+ Sct::SctFolder.create_folder!
16
+
17
+ setup = self.new
18
+ setup.write_Sctfile
19
+
20
+ end
21
+
22
+ def write_Sctfile
23
+
24
+ Sctfile_file_name = "Sctfile"
25
+
26
+ self.Sctfile_content = ""
27
+ self.Sctfile_content << "email=address@visma.com"
28
+
29
+ Sctfile_path = File.join(Sct::SctFolder.path, Sctfile_file_name)
30
+
31
+ File.write(Sctfile_path, self.Sctfile_content)
32
+
33
+ puts "Generated Sctfile at #{Sctfile_path}"
34
+
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,3 @@
1
+ module Sct
2
+ VERSION = "0.1.0"
3
+ end
data/sct.gemspec ADDED
@@ -0,0 +1,39 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "sct/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "sct"
7
+ spec.version = Sct::VERSION
8
+ spec.authors = ["Reshad Farid"]
9
+ spec.email = ["reshad.farid@visma.com"]
10
+
11
+ spec.summary = %q{Spend Cloud Tool.}
12
+ spec.description = %q{Spend Cloud Tool enables to setup a local development environment for the Spend Cloud.}
13
+ spec.homepage = "https://gitlab.com/proactive-software/packages/sct"
14
+ spec.license = "MIT"
15
+
16
+ # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
17
+
18
+ spec.metadata["homepage_uri"] = spec.homepage
19
+ spec.metadata["source_code_uri"] = "https://gitlab.com/proactive-software/packages/sct"
20
+ spec.metadata["changelog_uri"] = "https://gitlab.com/proactive-software/packages/sct"
21
+
22
+ # Specify which files should be added to the gem when it is released.
23
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
24
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
25
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
26
+ end
27
+ spec.bindir = "bin"
28
+ spec.executables = ["sct"]
29
+ spec.require_paths = ["lib"]
30
+
31
+ spec.add_dependency "class_interface"
32
+ spec.add_dependency "colored", "~> 1.2"
33
+ spec.add_dependency "hosts", "~> 0.1.1"
34
+ spec.add_dependency "commander", "~> 4.4.7"
35
+
36
+ spec.add_development_dependency "bundler", "~> 2.0"
37
+ spec.add_development_dependency "rake", "~> 10.0"
38
+ spec.add_development_dependency "rspec", "~> 3.0"
39
+ end
metadata ADDED
@@ -0,0 +1,174 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sct
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Reshad Farid
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-01-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: class_interface
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: colored
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.2'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.2'
41
+ - !ruby/object:Gem::Dependency
42
+ name: hosts
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.1.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.1.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: commander
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 4.4.7
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 4.4.7
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '2.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '2.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '10.0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '10.0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.0'
111
+ description: Spend Cloud Tool enables to setup a local development environment for
112
+ the Spend Cloud.
113
+ email:
114
+ - reshad.farid@visma.com
115
+ executables:
116
+ - sct
117
+ extensions: []
118
+ extra_rdoc_files: []
119
+ files:
120
+ - ".DS_Store"
121
+ - ".gitignore"
122
+ - ".rspec"
123
+ - ".travis.yml"
124
+ - CODE_OF_CONDUCT.md
125
+ - Gemfile
126
+ - Gemfile.lock
127
+ - LICENSE.txt
128
+ - README.md
129
+ - Rakefile
130
+ - bin/console
131
+ - bin/sct
132
+ - bin/setup
133
+ - lib/.DS_Store
134
+ - lib/sct.rb
135
+ - lib/sct/.DS_Store
136
+ - lib/sct/command.rb
137
+ - lib/sct/command_interface.rb
138
+ - lib/sct/command_option.rb
139
+ - lib/sct/commands/hostfile.rb
140
+ - lib/sct/commands/init.rb
141
+ - lib/sct/commands/mysqlproxy.rb
142
+ - lib/sct/constants.rb
143
+ - lib/sct/sct_folder.rb
144
+ - lib/sct/setup/helpers.rb
145
+ - lib/sct/setup/setup.rb
146
+ - lib/sct/version.rb
147
+ - sct.gemspec
148
+ homepage: https://gitlab.com/proactive-software/packages/sct
149
+ licenses:
150
+ - MIT
151
+ metadata:
152
+ homepage_uri: https://gitlab.com/proactive-software/packages/sct
153
+ source_code_uri: https://gitlab.com/proactive-software/packages/sct
154
+ changelog_uri: https://gitlab.com/proactive-software/packages/sct
155
+ post_install_message:
156
+ rdoc_options: []
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ requirements: []
170
+ rubygems_version: 3.0.6
171
+ signing_key:
172
+ specification_version: 4
173
+ summary: Spend Cloud Tool.
174
+ test_files: []