shards 1.1.3 → 1.1.6

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5487854a27b9cec585d3f15abaa1e49bab866833
4
- data.tar.gz: 05ac6850b43dc993a377dde0547d491650fd9912
3
+ metadata.gz: 8100a8736331fe754ed67615e90de445c142cf90
4
+ data.tar.gz: 3f9e7a44454e6265f2cb9a6298d5b562a7811e66
5
5
  SHA512:
6
- metadata.gz: 2b567b16d4430df54d0d0353a66911a47645c80e807bbfdc09d49d695c6785c5f70fc150b8175e7505507e0c20cb01729ec18f0bafdacc0f1d2890c3a04cb5d2
7
- data.tar.gz: 21be66fcf0e76b604b5a359e5d48182dbd5bc9629dbb0c655fda81e666685dba265a165d3534c5c39c1cd20f247805167d6e657db59fc1904540ba8ce3231967
6
+ metadata.gz: 9e34b61bc072e0c729f27a2519c2fed429bee35b5acaf029325c73ed4e13efcaee6669945fbb34f1b91b150fd56a9dc8d854a33d931b028c88edd4946c2c34c6
7
+ data.tar.gz: 83ab8355643ea330fe5d59dbd70686a42711ff4a165942a1c07fe35b39a763f3f9aa1e4aa7c706b7aec36e010eb74bbc6e49b8c29d25c61cb398c8dba710abc2
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- shards (1.1.3)
4
+ shards (1.1.6)
5
5
  aws-sdk-route53 (~> 1.9)
6
6
  dotenv (~> 2.4)
7
7
  git (~> 1.4)
data/README.md CHANGED
@@ -46,7 +46,8 @@ PROXY_USER=proxy_username
46
46
  TEST=true #only for test.env delete this var in settings.env
47
47
  CONFIG_REPLACE={ 'prod' => 'web' }
48
48
  LIVE_BRANCH=shards_test # set this var to use in test.env or to change the default value 'v5'
49
- WORKFLOW_YAML_FILE=path/to/your/workflow.yaml # write the path to your workflow yaml. You have to implement the existing methods.
49
+ WORKFLOW_YAML_PATH=path/to/your/workflows/ # you could overwrite yaml files using the same name in the defined path.
50
+
50
51
  # You could overwrite methods using this metaprograming way ading your on your_file.yaml
51
52
  # Then add this var:
52
53
  # FORMAT_METHODS_FILE=your/path/to/your_file.yaml
@@ -3,14 +3,38 @@ Shards::Dns:
3
3
  name: (domain + stage.get('domain_suffix')).downcase.gsub('_','-')
4
4
  zone: ENV['DNS_ZONE_CODE']
5
5
  target: stage.route53
6
- r53upsert: >
6
+ r53upsert: |
7
+ @action='UPSERT'
8
+ @begin_comment='Adding'
9
+ r53_operation
10
+
11
+ host: name + '.' + ENV['DOMAIN']
12
+ dryrun_message: |
13
+ add "##### DNS Dryrun #####"
14
+ add "CNAME: #{host}"
15
+ add "Target: #{target}"
16
+ add "ZoneID: #{zone}"
17
+ add " "
18
+ creating_route53_message: |
19
+ add "##### Setting Up DNS"
20
+ add "Creating Route53 entry for #{host} as a CNAME to #{target}"
21
+ add " "
22
+ aws_route53_record_message: |
23
+ add "Route53 Response"
24
+ add aws_route53_resp.to_h
25
+ r53delete: |
26
+ @action='DELETE'
27
+ @begin_comment='Deleting'
28
+ r53_operation
29
+
30
+ r53_operation: |
7
31
  {
8
32
  change_batch: {
9
33
  changes: [
10
34
  {
11
- action: "UPSERT",
35
+ action: action,
12
36
  resource_record_set: {
13
- name: host,
37
+ name: host_param,
14
38
  resource_records: [
15
39
  {
16
40
  value: target
@@ -21,25 +45,11 @@ Shards::Dns:
21
45
  },
22
46
  },
23
47
  ],
24
- comment: "Adding #{name} to #{ENV['DOMAIN']}"
48
+ comment: "#{begin_comment} record #{host_param} to #{target}"
25
49
  },
26
50
  hosted_zone_id: "#{zone}"
27
51
  }
28
52
 
29
- host: name + '.' + ENV['DOMAIN']
30
- dryrun_message: |
31
- add "##### DNS Dryrun #####"
32
- add "CNAME: #{host}"
33
- add "Target: #{target}"
34
- add "ZoneID: #{zone}"
35
- add " "
36
- creating_route53_message: |
37
- add "##### Setting Up DNS"
38
- add "Creating Route53 entry for #{host} as a CNAME to #{target}"
39
- add " "
40
- aws_route53_record_message: |
41
- add "Route53 Response"
42
- add aws_route53_resp.to_h
43
53
 
44
54
  Shards::Db:
45
55
  name: |
@@ -63,7 +73,7 @@ Shards::Db:
63
73
  inserting_data: |
64
74
  add "echo \"# Inserting data from #{net} into #{name}\""
65
75
  add "#{conn} #{name} < #{sql_dump_file}"
66
- conn: |
76
+ default_connection: |
67
77
  "mysql #{conn_usr_pass} -h#{server}"
68
78
  dump: |
69
79
  "mysqldump #{conn_usr_pass} -h#{net_server}"
@@ -94,6 +104,8 @@ Shards::Db:
94
104
  { 'host' => server , 'adapter' => adapter, 'reconnect' => reconnect , 'username' => user , 'password' => password , 'database' => name }
95
105
  show_command: |
96
106
  conn + ' -N -B -e "show databases"'
107
+ drop_command: |
108
+ conn + '-v -v -e "DROP DATABASE ' + database_to_drop + '"'
97
109
 
98
110
 
99
111
  Shards::Site:
@@ -0,0 +1,60 @@
1
+ ---
2
+ # these steps are shared
3
+ shared_steps:
4
+
5
+ check_shard_presence_in_shards:
6
+ wrong_message: The shard %s exists in shards.
7
+ correct: check_database_presence_in_server
8
+ wrong: finish
9
+
10
+ check_database_presence_in_server:
11
+ wrong_message: The database %s exists in server %s.
12
+ correct: check_domain_dns_presence
13
+ wrong: finish
14
+
15
+ check_domain_dns_presence:
16
+ wrong_message: There is already a record for the host %s.
17
+ correct: check_domain_presence_in_sites
18
+ wrong: finish
19
+
20
+ check_domain_presence_in_sites:
21
+ wrong_message: The domain %s is already present in sites.
22
+ correct: write_yaml_files
23
+ wrong: finish
24
+
25
+ write_yaml_files:
26
+ question: Type Y to confirm the changes
27
+ wrong_message: Undo changes
28
+ correct: create_database
29
+ wrong: clean_repo_and_exit
30
+
31
+ validate_location:
32
+ correct: validate_stage
33
+ wrong_message: Location %s does not exist.
34
+ wrong: clean_repo_and_exit
35
+
36
+ create_database:
37
+ message: The database %s has been successfully created in %s.
38
+ wrong_message: Error. Couldn't create the database %s in %s.
39
+ correct: commit_changes
40
+ wrong: clean_repo_and_exit
41
+
42
+ commit_changes:
43
+ message: The changes has been committed and pushed to the remote repository.
44
+ wrong_message: We had an issue to commit and push the changes.
45
+ correct: dns_upsert
46
+ wrong: finish
47
+
48
+ dns_upsert:
49
+ message: The dns record with the host %s has been succesfully created.
50
+ wrong_message: Error. Could not register the host %s as a dns record.
51
+ correct: finish
52
+ wrong: finish
53
+
54
+ clean_repo_and_exit:
55
+ wrong_message: Cuould not clean the repository.
56
+ correct: finish
57
+
58
+ finish:
59
+ correct: final_step
60
+
@@ -0,0 +1,45 @@
1
+ ---
2
+ # see shared_steps in base.yaml to find the steps not defined in a workflow
3
+
4
+ delete_by_terminal:
5
+
6
+ validate_stage:
7
+ correct: validate_subdomain
8
+ wrong_message: Stage %s does not exist.
9
+ wrong: finish
10
+
11
+ validate_subdomain:
12
+ correct: delete_record
13
+ wrong_message: Host %s has not a recordset to target %s.
14
+ wrong: finish
15
+
16
+ delete_record:
17
+ message: Record %s deleted in target %s
18
+ correct: delete_site_and_shard
19
+ wrong: finish
20
+ wrong_message: Could not delete the record %s.
21
+
22
+ delete_site_and_shard:
23
+ correct: write_yaml_files
24
+ wrong: clean_repo_and_exit
25
+ wrong_message: Could not delete site or shard.\n %s.
26
+
27
+ write_yaml_files:
28
+ question: Type Y to confirm the changes
29
+ wrong_message: Undo changes
30
+ correct: commit_changes
31
+ wrong: clean_repo_and_exit
32
+
33
+ commit_changes:
34
+ message: The changes has been committed and pushed to the remote repository.
35
+ wrong_message: We had an issue to commit and push the changes.
36
+ correct: delete_database
37
+ wrong: finish
38
+
39
+ delete_database:
40
+ wrong_message: The database %s could not be deleted in host %s.
41
+ message: Database %s was deleted in host %s.
42
+ correct: finish
43
+ wrong: finish
44
+
45
+ start: validate_location
@@ -0,0 +1,24 @@
1
+ ---
2
+ # see shared_steps in base.yaml to find the steps not defined in a workflow
3
+
4
+ fast_terminal:
5
+
6
+ validate_client:
7
+ correct: validate_domain
8
+ wrong: clean_repo_and_exit
9
+ wrong_message: The client name %s.
10
+ min_size: 2
11
+
12
+ validate_domain:
13
+ correct: validate_location
14
+ wrong: clean_repo_and_exit
15
+ wrong_message: The domain %s.
16
+ min_size: 3
17
+ regex: ^[a-zA-Z0-9_]*$
18
+
19
+ validate_stage:
20
+ correct: check_shard_presence_in_shards
21
+ wrong_message: Stage %s does not exist.
22
+ wrong: clean_repo_and_exit
23
+
24
+ start: validate_client
@@ -0,0 +1,48 @@
1
+ ---
2
+ # see shared_steps in base.yaml to find the steps not defined in a workflow
3
+ terminal:
4
+
5
+ ask_client:
6
+ question: Type the client name, please.
7
+ wrong_message: The client name %s.
8
+ correct: ask_location
9
+ wrong: ask_for_repeat
10
+ min_size: 2
11
+
12
+ ask_location:
13
+ question: Type the location mumber, please.
14
+ wrong_message: The location %s is not in the list.
15
+ correct: ask_stage
16
+ wrong: ask_for_repeat
17
+
18
+ ask_stage:
19
+ question: Type stage number, please.
20
+ wrong_message: The stage %s is not in the list.
21
+ correct: ask_domain
22
+ wrong: ask_for_repeat
23
+
24
+ ask_domain:
25
+ question: Type the domain name, please.
26
+ wrong_message: The domain name %s.
27
+ correct: check_shard_presence_in_shards
28
+ wrong: ask_for_repeat
29
+ min_size: 3
30
+ regex: ^[a-zA-Z0-9_]*$
31
+
32
+ ask_for_exit_and_restart:
33
+ question: Type 'r' to restart the process, another key to finish.
34
+ wrong_message: Process Interrupted.
35
+ correct: ask_location
36
+ wrong: finish
37
+
38
+ ask_for_repeat:
39
+ question: Wrong answer, type 'r' to repeat the step, another key to finish.
40
+ correct: repeat_previous_method
41
+ wrong_message: Process Interrupted. Cleanning the repo and exit.
42
+ wrong: finish
43
+
44
+ repeat_previous_method:
45
+ correct: repeat_previous_method
46
+ wrong: finish
47
+
48
+ start: ask_client
data/lib/shards/base.rb CHANGED
@@ -6,6 +6,8 @@ module Shards
6
6
 
7
7
  include Shards::Meta
8
8
 
9
+ attr_writer :subdomain_param
10
+
9
11
  class << self
10
12
 
11
13
  def method_list class_name
@@ -20,6 +22,11 @@ module Shards
20
22
  @config=get_config self.class.name
21
23
  end
22
24
 
25
+ def subdomain_param
26
+ @subdomain_param + '.' + ENV['DOMAIN'] unless @subdomain_param.nil?
27
+ end
28
+
29
+
23
30
  end
24
31
  end
25
32
 
data/lib/shards/client.rb CHANGED
@@ -16,6 +16,16 @@ module Shards
16
16
 
17
17
  end
18
18
 
19
+ desc 'delete LOCATION STAGE SUBDOMAIN', 'Fast deletion tool. To delete dns record, shard, site and database.'
20
+
21
+ def delete location, stage, subdomain
22
+
23
+ terminal=Shards::Workflow::DeleteByTerminal.new config
24
+ terminal.params= { subdomain: subdomain, location: location, stage: stage }
25
+ terminal.start
26
+
27
+ end
28
+
19
29
  desc 'terminal', 'Run interactive shards creation tool in the terminal'
20
30
 
21
31
  def terminal
@@ -72,11 +82,40 @@ module Shards
72
82
 
73
83
  def dns(location, stage, domain)
74
84
 
75
- s = get_stage location, stage
76
- s.shard.add_domain domain
77
- dns=s.shard.dns
85
+ d = get_dns location, stage, domain
86
+
87
+ puts "Host: #{d.host} , exists: #{d.exist?}"
78
88
 
79
- puts "Host: #{dns.host} , exists: #{dns.exist?}"
89
+ end
90
+
91
+ desc "subdomain_dns LOCATION STAGE SUBDOMAIN", "Check if dns record is available for a subdomain"
92
+
93
+ def subdomain_dns(location, stage, subdomain)
94
+
95
+ d = get_dns location, stage
96
+
97
+ d.subdomain_param=subdomain
98
+
99
+ puts "Subdomain: #{subdomain} , exists: #{d.exist?}"
100
+
101
+ end
102
+
103
+ desc "delete_subdomain_record LOCATION STAGE SUBDOMAIN", "Delete subdomain dns record"
104
+
105
+ def delete_subdomain_record(location, stage, subdomain)
106
+
107
+ d = get_dns location, stage
108
+
109
+ d.subdomain_param=subdomain
110
+
111
+ exist=d.exist?
112
+
113
+ puts "Subdomain: #{subdomain} , exists: #{exist}"
114
+
115
+ if exist
116
+ d.delete
117
+ puts "Host: #{d.host_param} deleted!"
118
+ end
80
119
 
81
120
  end
82
121
 
@@ -84,14 +123,12 @@ module Shards
84
123
 
85
124
  def add_dns_record(location, stage, domain)
86
125
 
87
- s = get_stage location, stage
88
- s.shard.add_domain domain
89
- dns=s.shard.dns
126
+ d = get_dns location, stage, domain
90
127
 
91
- if dns.exist?
92
- puts "There is already a record for the host %s " % dns.host
128
+ if d.exist?
129
+ puts "There is already a record for the host %s " % d.host
93
130
  else
94
- dns.set dryrun: false
131
+ d.set dryrun: false
95
132
  end
96
133
 
97
134
  end
@@ -128,6 +165,11 @@ module Shards
128
165
  l.stages[stage]
129
166
  end
130
167
 
168
+ def get_dns location, stage, domain=nil
169
+ s = get_stage location, stage
170
+ Shards::Dns.new stage: s, domain: domain
171
+ end
172
+
131
173
  end
132
174
 
133
175
  end
data/lib/shards/db.rb CHANGED
@@ -12,7 +12,9 @@ module Shards
12
12
  define_method(m.to_sym) { run __method__ }
13
13
  end
14
14
 
15
+ attr_accessor :database_to_drop
15
16
  attr_reader :stage, :dns, :databases_on_server
17
+ attr_writer :conn
16
18
 
17
19
  def initialize stage:, dns:
18
20
  set_config
@@ -82,9 +84,24 @@ module Shards
82
84
  @databases_on_server=ssh_output.split("\n").reject { |x| x.include?"Warning" }
83
85
  end
84
86
 
85
- def exist?
87
+ def exist? searched=nil
88
+ searched||=name
86
89
  show
87
- databases_on_server.include? name
90
+ databases_on_server.include? searched
91
+ end
92
+
93
+ def conn
94
+ @conn || default_connection
95
+ end
96
+
97
+ def drop
98
+
99
+ raise "database_to_drop is nil" if database_to_drop.nil?
100
+
101
+ ssh_conn do |ssh|
102
+ add(ssh.exec! drop_command)
103
+ end
104
+
88
105
  end
89
106
 
90
107
  end
data/lib/shards/dns.rb CHANGED
@@ -9,13 +9,13 @@ module Shards
9
9
  define_method(m.to_sym) { run __method__ }
10
10
  end
11
11
 
12
- attr_reader :stage, :domain
12
+ attr_reader :stage, :domain, :action, :begin_comment
13
13
  attr_accessor :aws_route53_resp, :r53
14
14
 
15
- def initialize stage:, domain:
15
+ def initialize stage:, domain: nil
16
16
  set_config
17
17
  @stage=stage
18
- @domain=domain.downcase
18
+ @domain=domain.downcase if domain
19
19
  reset_output
20
20
  @r53 = Aws::Route53::Client.new()
21
21
  end
@@ -35,22 +35,30 @@ module Shards
35
35
  @aws_route53_resp = r53.change_resource_record_sets r53upsert
36
36
  end
37
37
 
38
+ def delete
39
+ @aws_route53_resp = r53.change_resource_record_sets r53delete
40
+ end
41
+
38
42
  def exist?
39
- !record_list.empty?
43
+ !record_list(host_param).empty?
40
44
  end
41
45
 
42
- def record_list
43
- record_sets.select { |x| x.name.include? host }
46
+ def record_list host_param
47
+ record_sets(host_param).select { |x| x.name.include? host_param }
44
48
  end
45
49
 
46
- def record_sets
50
+ def record_sets host_param
47
51
  r53.list_resource_record_sets({
48
52
  hosted_zone_id: zone,
49
- start_record_name: host,
53
+ start_record_name: host_param,
50
54
  max_items: 20
51
55
  }).resource_record_sets
52
56
  end
53
57
 
58
+ def host_param
59
+ subdomain_param || host
60
+ end
61
+
54
62
  end
55
63
  end
56
64
 
data/lib/shards/shard.rb CHANGED
@@ -8,7 +8,8 @@ module Shards
8
8
  define_method(m.to_sym) { run __method__ }
9
9
  end
10
10
 
11
- attr_accessor :domain, :db, :dns
11
+ attr_accessor :domain, :db, :dns, :database
12
+ attr_writer :name_param
12
13
 
13
14
  def shard_list_key
14
15
  ENV['SHARD_LIST_KEY_ROOT_PATH'].split.map do |k|
@@ -55,8 +56,34 @@ module Shards
55
56
  write_yaml
56
57
  end
57
58
 
59
+ def name_param
60
+ @name_param || name
61
+ end
62
+
58
63
  def exist?
59
- list.keys.include? name
64
+ list.keys.include? name_param
65
+ end
66
+
67
+ def delete
68
+ raise "#{name_param} doesn't exist" unless exist?
69
+ @database=list[name_param]
70
+ delete_in_yaml
71
+ write_yaml
72
+ end
73
+
74
+ def delete_in_yaml
75
+ list_to_delete=list.clone
76
+ list_to_delete.delete name_param
77
+ eval "@yaml#{shard_list_key.to_s}=list_to_delete"
78
+ end
79
+
80
+ def by_database
81
+ raise "database is nil" if database.nil?
82
+ list.select { |k,v| v['database']==database['database'] }
83
+ end
84
+
85
+ def count_by_database
86
+ by_database.keys.count
60
87
  end
61
88
 
62
89
  end
data/lib/shards/site.rb CHANGED
@@ -4,7 +4,7 @@ module Shards
4
4
 
5
5
  class Site < BaseYamlObject
6
6
 
7
- attr_accessor :client
7
+ attr_accessor :client, :shard
8
8
 
9
9
  method_list('Shards::Site').each do |m|
10
10
  define_method(m.to_sym) { run __method__ }
@@ -22,8 +22,33 @@ module Shards
22
22
 
23
23
  end
24
24
 
25
+ def domain_param
26
+ subdomain_param || domain
27
+ end
28
+
25
29
  def exist?
26
- !yaml.select { |x| x['domain']==domain }.empty?
30
+ !select_by_domain.empty?
31
+ end
32
+
33
+ def select_by_domain
34
+ yaml.select { |x| x['domain']==domain_param }
35
+ end
36
+
37
+ def reject_by_domain
38
+ yaml.reject { |x| x['domain']==domain_param }
39
+ end
40
+
41
+ def select_by_shard
42
+ yaml.select { |x| x['shard']==shard }
43
+ end
44
+
45
+ def delete
46
+ site_to_delete = select_by_domain
47
+ raise "there are more than one site with this domain" if site_to_delete.count > 1
48
+ raise "there are not a site with this domain" if site_to_delete.count < 1
49
+ @shard=site_to_delete.first['shard']
50
+ @yaml=reject_by_domain
51
+ write_yaml
27
52
  end
28
53
 
29
54
  end
@@ -1,3 +1,3 @@
1
1
  module Shards
2
- VERSION = "1.1.3"
2
+ VERSION = "1.1.6"
3
3
  end
@@ -6,27 +6,68 @@ module Shards
6
6
 
7
7
  class Base
8
8
 
9
- attr_accessor :yaml, :config, :flow, :pointer, :step, :answer, :pointer_history, :client, :location, :stage, :domain, :site, :params
9
+ attr_accessor :config, :flow, :pointer, :step, :answer, :pointer_history, :client, :location, :stage, :domain, :site, :params
10
+
11
+ attr_writer :wf
12
+
10
13
 
11
14
  def initialize config
12
15
  @config=config
13
16
  config.repo.clean
14
- @yaml= YAML.load_file file
15
17
  @pointer_history = []
16
18
  end
17
19
 
20
+ def yaml
21
+ @yaml||= YAML.load_file file
22
+ end
23
+
18
24
  def file
19
- ENV['WORKFLOW_YAML_FILE'] || default_file
25
+ get_file "#{wf}.yaml"
26
+ end
27
+
28
+ def shared_file
29
+ get_file 'base.yaml'
30
+ end
31
+
32
+ def shared_steps
33
+ YAML.load_file(shared_file)['shared_steps']
34
+ end
35
+
36
+ def get_file fname
37
+
38
+ f=File.join path, fname
39
+
40
+ f=File.join default_path, fname unless File.exist? f
41
+
42
+ f
43
+
44
+ end
45
+
46
+ def path
47
+ ENV['WORKFLOW_YAML_PATH'] || default_path
48
+ end
49
+
50
+ def default_path
51
+ File.join Shards.root_path, %w(lib settings workflows)
20
52
  end
21
53
 
22
- def default_file
23
- File.join Shards.root_path, %w(lib settings workflow.yaml)
54
+ def wf
55
+ @wf || decamelize( self.class.name.split('::').last )
24
56
  end
25
57
 
26
- def start wf=nil
27
- wf||=self.class.name.split('::').last.downcase
28
- @flow=yaml[wf].merge yaml['shared_steps']
29
- @pointer=flow.keys.first
58
+ def decamelize camelcase
59
+ camelcase.
60
+ gsub(/([A-Z\d]+)([A-Z][a-z])/, '\1_\2').
61
+ gsub(/([a-z]+)([A-Z\d])/, '\1_\2').
62
+ gsub(/([A-Z]{2,})(\d+)/i, '\1_\2').
63
+ gsub(/(\d+)([a-z])/i, '\1_\2').
64
+ gsub(/(.+?)\&(.+?)/, '\1_&_\2').
65
+ gsub(/\s/, '_').downcase
66
+ end
67
+
68
+ def start
69
+ @flow=shared_steps.merge yaml[wf]
70
+ @pointer=yaml['start']
30
71
  run_step
31
72
  end
32
73
 
@@ -174,6 +215,18 @@ module Shards
174
215
  raise step['wrong_message'] if answer.strip.downcase!='r'
175
216
  end
176
217
 
218
+ def validate_location
219
+ loc=params[:location]
220
+ raise_wrong_text loc unless config.locations.keys.include? loc
221
+ @location=config.locations[loc]
222
+ end
223
+
224
+ def validate_stage
225
+ st=params[:stage]
226
+ raise_wrong_text st unless location.stages.keys.include? st
227
+ @stage=location.stages[st]
228
+ end
229
+
177
230
  end
178
231
 
179
232
  end
@@ -0,0 +1,83 @@
1
+ require_relative './base.rb'
2
+
3
+ module Shards
4
+
5
+ module Workflow
6
+
7
+ class DeleteByTerminal < Shards::Workflow::Base
8
+
9
+ attr_accessor :dns, :db, :db_conn
10
+
11
+ def validate_subdomain
12
+ @dns=Shards::Dns.new stage: stage
13
+ dns.subdomain_param=params[:subdomain]
14
+ raise_wrong_text [dns.host_param, dns.target] unless dns.exist?
15
+ end
16
+
17
+ def delete_record
18
+ dns.delete
19
+ message_params= [dns.host_param, dns.target]
20
+ raise_wrong_text message_params if dns.exist?
21
+ puts step['message'] % message_params
22
+ end
23
+
24
+ def delete_site_and_shard
25
+ site=Shards::Site.new stage
26
+ site.subdomain_param=params[:subdomain]
27
+ site.delete
28
+
29
+ shard=Shards::Shard.new stage
30
+ @shard_name= site.shard
31
+ shard.name_param = @shard_name
32
+ shard.delete
33
+
34
+ @db_conn=shard.database
35
+
36
+ end
37
+
38
+ def write_yaml_files
39
+ puts config.repo.diff
40
+ ask_question
41
+ raise step['wrong_message'] if answer.strip.downcase!='y'
42
+ end
43
+
44
+ def commit_changes
45
+ config.repo.message = "Deleted site: #{params[:subdomain]} and shard: #{@shard_name} in #{location.name}"
46
+ config.repo.autocommit
47
+ puts step['message']
48
+ puts config.repo.message
49
+ end
50
+
51
+ def delete_database
52
+ @db=Shards::Db.new stage: stage, dns: dns
53
+ message_params= [db_name, db_host]
54
+ raise "Database %s does not exist in %s." % message_params unless db_exist?
55
+
56
+ db.database_to_drop=db_name
57
+ db.conn="mysql -u#{db_conn['username']} -p#{db_conn['password']} -h#{db_host} "
58
+ db.drop
59
+
60
+ raise_wrong_text message_params if db_exist?
61
+ puts step['message'] % message_params
62
+ end
63
+
64
+
65
+ private
66
+
67
+ def db_exist?
68
+ db.exist? db_conn['database']
69
+ end
70
+
71
+ def db_name
72
+ db_conn['database']
73
+ end
74
+
75
+ def db_host
76
+ db_conn['host']
77
+ end
78
+
79
+ end
80
+
81
+ end
82
+
83
+ end
@@ -16,18 +16,6 @@ module Shards
16
16
 
17
17
  end
18
18
 
19
- def validate_location
20
- loc=params[:location]
21
- raise_wrong_text loc unless config.locations.keys.include? loc
22
- @location=config.locations[loc]
23
- end
24
-
25
- def validate_stage
26
- st=params[:stage]
27
- raise_wrong_text st unless location.stages.keys.include? st
28
- @stage=location.stages[st]
29
- end
30
-
31
19
  def validate_domain
32
20
 
33
21
  domain_name=params[:domain]
@@ -1,6 +1,7 @@
1
1
  require "shards/workflow/base"
2
2
  require "shards/workflow/terminal"
3
3
  require "shards/workflow/fast_terminal"
4
+ require "shards/workflow/delete_by_terminal"
4
5
 
5
6
  module Shards
6
7
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: shards
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.3
4
+ version: 1.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Diego PL
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-08-01 00:00:00.000000000 Z
11
+ date: 2018-08-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -201,7 +201,10 @@ files:
201
201
  - bin/setup
202
202
  - exe/shards
203
203
  - lib/settings/format_methods.yaml
204
- - lib/settings/workflow.yaml
204
+ - lib/settings/workflows/base.yaml
205
+ - lib/settings/workflows/delete_by_terminal.yaml
206
+ - lib/settings/workflows/fast_terminal.yaml
207
+ - lib/settings/workflows/terminal.yaml
205
208
  - lib/shards.rb
206
209
  - lib/shards/base.rb
207
210
  - lib/shards/base_yaml_object.rb
@@ -218,6 +221,7 @@ files:
218
221
  - lib/shards/stage.rb
219
222
  - lib/shards/version.rb
220
223
  - lib/shards/workflow/base.rb
224
+ - lib/shards/workflow/delete_by_terminal.rb
221
225
  - lib/shards/workflow/fast_terminal.rb
222
226
  - lib/shards/workflow/terminal.rb
223
227
  - lib/shards/workflow/workflow.rb
@@ -1,126 +0,0 @@
1
- ---
2
- # see shared_steps to find the steps not defined in a workflow
3
- terminal:
4
-
5
- ask_client:
6
- question: Type the client name, please.
7
- wrong_message: The client name %s.
8
- correct: ask_location
9
- wrong: ask_for_repeat
10
- min_size: 2
11
-
12
- ask_location:
13
- question: Type the location mumber, please.
14
- wrong_message: The location %s is not in the list.
15
- correct: ask_stage
16
- wrong: ask_for_repeat
17
-
18
- ask_stage:
19
- question: Type stage number, please.
20
- wrong_message: The stage %s is not in the list.
21
- correct: ask_domain
22
- wrong: ask_for_repeat
23
-
24
- ask_domain:
25
- question: Type the domain name, please.
26
- wrong_message: The domain name %s.
27
- correct: check_shard_presence_in_shards
28
- wrong: ask_for_repeat
29
- min_size: 3
30
- regex: ^[a-zA-Z0-9_]*$
31
-
32
- ask_for_exit_and_restart:
33
- question: Type 'r' to restart the process, another key to finish.
34
- wrong_message: Process Interrupted.
35
- correct: ask_location
36
- wrong: finish
37
-
38
- ask_for_repeat:
39
- question: Wrong answer, type 'r' to repeat the step, another key to finish.
40
- correct: repeat_previous_method
41
- wrong_message: Process Interrupted. Cleanning the repo and exit.
42
- wrong: finish
43
-
44
- repeat_previous_method:
45
- correct: repeat_previous_method
46
- wrong: finish
47
-
48
-
49
- fastterminal:
50
-
51
- validate_client:
52
- correct: validate_domain
53
- wrong: clean_repo_and_exit
54
- wrong_message: The client name %s.
55
- min_size: 2
56
-
57
- validate_domain:
58
- correct: validate_location
59
- wrong: clean_repo_and_exit
60
- wrong_message: The domain %s.
61
- min_size: 3
62
- regex: ^[a-zA-Z0-9_]*$
63
-
64
- validate_location:
65
- correct: validate_stage
66
- wrong_message: Location %s does not exist.
67
- wrong: clean_repo_and_exit
68
-
69
- validate_stage:
70
- correct: check_shard_presence_in_shards
71
- wrong_message: Stage %s does not exist.
72
- wrong: clean_repo_and_exit
73
-
74
- shared_steps:
75
-
76
- check_shard_presence_in_shards:
77
- wrong_message: The shard %s exists in shards.
78
- correct: check_database_presence_in_server
79
- wrong: finish
80
-
81
- check_database_presence_in_server:
82
- wrong_message: The database %s exists in server %s.
83
- correct: check_domain_dns_presence
84
- wrong: finish
85
-
86
- check_domain_dns_presence:
87
- wrong_message: There is already a record for the host %s.
88
- correct: check_domain_presence_in_sites
89
- wrong: finish
90
-
91
- check_domain_presence_in_sites:
92
- wrong_message: The domain %s is already present in sites.
93
- correct: write_yaml_files
94
- wrong: finish
95
-
96
- write_yaml_files:
97
- question: Type Y to confirm the changes
98
- wrong_message: Undo changes
99
- correct: create_database
100
- wrong: clean_repo_and_exit
101
-
102
- create_database:
103
- message: The database %s has been successfully created in %s.
104
- wrong_message: Error. Couldn't create the database %s in %s.
105
- correct: commit_changes
106
- wrong: clean_repo_and_exit
107
-
108
- commit_changes:
109
- message: The changes has been committed and pushed to the remote repository.
110
- wrong_message: We had an issue to commit and push the changes.
111
- correct: dns_upsert
112
- wrong: finish
113
-
114
- dns_upsert:
115
- message: The dns record with the host %s has been succesfully created.
116
- wrong_message: Error. Could not register the host %s as a dns record.
117
- correct: finish
118
- wrong: finish
119
-
120
- clean_repo_and_exit:
121
- wrong_message: Cuould not clean the repository.
122
- correct: finish
123
-
124
- finish:
125
- correct: final_step
126
-