souls 1.19.3 → 1.19.7

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
  SHA256:
3
- metadata.gz: d4bf137864959be7746651e84876c0519fdcf40b11bb87b09ac1f52b0a5c6fa7
4
- data.tar.gz: e0e0ad235cf3aac9fa1588b0b7c147c0a55549e9aab455c9314d25ec7bed1d57
3
+ metadata.gz: 7397cc9eb56f0420edff1764b05af2411bc28df50fcaacf53e1babc6af2531d1
4
+ data.tar.gz: fb3283fb3e09e06e1e37f00870f9d9f577fac509cd2564d2f97cf9be0d614f37
5
5
  SHA512:
6
- metadata.gz: 437ac90c2f77121b62b6f50a7b88219234ac261dba30dfb99e9961bf3e402c3e71d2252489cff14058701c0850c6238e633721a9ac7686d564da658b21aafbf7
7
- data.tar.gz: 8268a01caf6ca481bc77e0977fa52a78359f68e0b2cfaa164a6e93c9ea4c0be08e29de27a600a025c836cd4337923c3e19bbe63ae08348ea921457d571b4194b
6
+ metadata.gz: 9c164ae100be15a59717e16d991f8fb4ce3520eca314a16d3e82dfd6f54b87eed01ea99efd56a86e8d6a68cedc9999b103713696ae06f395f8898597ccd2b34f
7
+ data.tar.gz: ecbb2177e6ba224cea34fba5b8f7af6951c8dbfdc49a45e60f33d3df7e60fb7c9c6b3051733cba703c784e6af4fcc43d5f173c60afd56350c4b3b653cb8d4f50
@@ -13,16 +13,28 @@ module SOULs
13
13
  puts(Paint % ["✓ %{white_text}", :red, { white_text: ["Deleted file #{text}", :white] }])
14
14
  end
15
15
 
16
- def error(text)
17
- puts(Paint["🚨 #{text}", :red])
16
+ def error(text, emoji = nil)
17
+ if emoji
18
+ puts(Paint["#{emoji} #{text}", :red])
19
+ else
20
+ puts(Paint["🚨 #{text}", :red])
21
+ end
18
22
  end
19
23
 
20
- def warning(text)
21
- puts(Paint["🚨 #{text}", :yellow])
24
+ def warning(text, emoji = nil)
25
+ if emoji
26
+ puts(Paint["#{emoji} #{text}", :yellow])
27
+ else
28
+ puts(Paint["🚨 #{text}", :yellow])
29
+ end
22
30
  end
23
31
 
24
- def success(text)
25
- puts(Paint["🎉 #{text}", :green])
32
+ def success(text, emoji = nil)
33
+ if emoji
34
+ puts(Paint["#{emoji} #{text}", :green])
35
+ else
36
+ puts(Paint["🎉 #{text}", :green])
37
+ end
26
38
  end
27
39
 
28
40
  def sync(text)
@@ -1,7 +1,6 @@
1
1
  module Template
2
2
  module Go
3
3
  def self.function(file_name)
4
- file_name.underscore.camelize
5
4
  <<~APP
6
5
  // Package p contains an HTTP Cloud Function.
7
6
  package p
@@ -17,7 +16,7 @@ module Template
17
16
 
18
17
  // HelloWorld prints the JSON encoded "message" field in the body
19
18
  // of the request or "Hello, World!" if there isn't one.
20
- func #{file_name}(w http.ResponseWriter, r *http.Request) {
19
+ func #{file_name.underscore.camelize}(w http.ResponseWriter, r *http.Request) {
21
20
  var d struct {
22
21
  Message string `json:"message"`
23
22
  }
@@ -1,7 +1,6 @@
1
1
  module Template
2
2
  module Nodejs
3
3
  def self.index(file_name)
4
- file_name.underscore.camelize(:lower)
5
4
  <<~APP
6
5
  const express = require('express');
7
6
  const bodyParser = require('body-parser');
@@ -20,7 +19,7 @@ module Template
20
19
  app.post('/souls-functions-post', (req, res)=>{
21
20
  res.json(req.body)
22
21
  });
23
- exports.#{file_name} = app;
22
+ exports.#{file_name.underscore.camelize(:lower)} = app;
24
23
  APP
25
24
  end
26
25
  end
@@ -1,9 +1,8 @@
1
1
  module Template
2
2
  module Python
3
3
  def self.main(file_name)
4
- file_name.underscore
5
4
  <<~APP
6
- def #{file_name}(request):
5
+ def #{file_name.underscore}(request):
7
6
  """Responds to any HTTP request.
8
7
  Args:
9
8
  request (flask.Request): HTTP request object.
@@ -2,23 +2,28 @@ module SOULs
2
2
  class Iam < Thor
3
3
  desc "setup_key", "Create Google Cloud IAM Service Account Key And Set All Permissions"
4
4
  def setup_key
5
- region = SOULs.configuration.region
6
- SOULs::Gcloud.new.auth_login
7
- SOULs::Upgrade.new.config
8
- create_service_account
9
- create_service_account_key
10
- SOULs::Gcloud.new.enable_permissions
11
- add_permissions
12
- begin
13
- system("gcloud app create --region=#{region} --quiet")
14
- rescue StandardError, error
15
- puts("gcloud app region is Already exist! - SOULs::Gcloud::Iam.setup_key")
16
- end
17
- begin
18
- set_gh_secret_json
19
- rescue StandardError
20
- export_key_to_console
5
+ Whirly.start(spinner: "clock", interval: 420, stop: "🎉") do
6
+ Whirly.status = "Setting up credentials and permissions..."
7
+ region = SOULs.configuration.region
8
+ SOULs::Gcloud.new.auth_login
9
+ SOULs::Upgrade.new.config
10
+ create_service_account
11
+ create_service_account_key
12
+ SOULs::Gcloud.new.enable_permissions
13
+ add_permissions
14
+ begin
15
+ system("gcloud app create --region=#{region} --quiet")
16
+ rescue StandardError, error
17
+ puts("gcloud app region is Already exist! - SOULs::Gcloud::Iam.setup_key")
18
+ end
19
+ begin
20
+ set_gh_secret_json
21
+ rescue StandardError
22
+ export_key_to_console
23
+ end
21
24
  end
25
+ SOULs::Painter.success("You're all set!")
26
+ true
22
27
  end
23
28
 
24
29
  private
@@ -62,6 +62,8 @@ module SOULs
62
62
  system("gcloud services enable cloudresourcemanager.googleapis.com")
63
63
  system("gcloud services enable translate.googleapis.com")
64
64
  system("gcloud services enable firestore.googleapis.com")
65
+ system("gcloud services enable cloudfunctions.googleapis.com")
66
+ system("gcloud services enable cloudbuild.googleapis.com")
65
67
  end
66
68
  end
67
69
  end
@@ -6,7 +6,6 @@ module SOULs
6
6
  def create_instance
7
7
  prompt = TTY::Prompt.new
8
8
  password = prompt.mask("Set DB PassWord:")
9
- app_name = SOULs.configuration.app
10
9
  project_id = SOULs.configuration.project_id
11
10
  instance_name = SOULs.configuration.instance_name
12
11
  region = SOULs.configuration.region if options[:region].blank?
@@ -20,43 +19,57 @@ module SOULs
20
19
  --database-version=#{db_type} --cpu=1 --memory=4096MB --zone=#{zone} \
21
20
  --root-password='#{password}' --database-flags cloudsql.iam_authentication=on"
22
21
  )
23
- instance_ip = `gcloud sql instances list | grep #{instance_name} | awk '{print $5}'`.strip
24
- Dir.chdir(SOULs.get_api_path.to_s) do
25
- file_path = ".env"
26
- File.open(file_path, "w") do |line|
27
- line.write(<<~TEXT)
28
- GOOGLE_AUTH_SUPPRESS_CREDENTIALS_WARNINGS=1
29
- SOULS_DB_HOST=#{instance_ip}
30
- SOULS_DB_PW=#{password}
31
- SOULS_DB_USER=postgres
32
- SOULS_GCP_PROJECT_ID=#{project_id}
33
- SOULS_SECRET_KEY_BASE='#{SecureRandom.base64(64)}'
34
- TZ="#{region_to_timezone(region: region)}"
35
- TEXT
36
- end
37
- end
38
- Dir.chdir(SOULs.get_mother_path.to_s) do
39
- file_path = ".env.production"
40
- File.open(file_path, "w") do |line|
41
- line.write(<<~TEXT)
42
- SOULS_DB_HOST="/cloudsql/#{project_id}:#{region}:#{instance_name}"
43
- SOULS_DB_PW=#{password}
44
- SOULS_DB_USER=postgres
45
- SOULS_APP_NAME=#{app_name}
46
- SOULS_GCP_PROJECT_ID=#{project_id}
47
- SOULS_GCP_REGION=#{region}
48
- SOULS_GCLOUDSQL_INSTANCE="#{project_id}:#{region}:#{instance_name}"
49
- SOULS_SECRET_KEY_BASE='#{SecureRandom.base64(64)}'
50
- TZ="#{region_to_timezone(region: region)}"
51
- TEXT
52
- end
53
- end
22
+ SOULs::Sql.new.env(password: password)
54
23
  SOULs::Github.new.secret_set
55
24
  Whirly.status = Paint["Cloud SQL #{instance_name} is successfully created! You can push to deploy!", :green]
56
25
  end
57
26
  true
58
27
  end
59
28
 
29
+ desc "env", "Generate .env.production file to deploy"
30
+ def env(password: "Password")
31
+ require(SOULs.get_mother_path.to_s + "/config/souls")
32
+ project_id = SOULs.configuration.project_id
33
+ instance_name = SOULs.configuration.instance_name
34
+ region = SOULs.configuration.region
35
+ app_name = SOULs.configuration.app
36
+ prompt = TTY::Prompt.new
37
+ db_password = password == "Password" ? prompt.mask("Set DB PassWord:") : password
38
+ instance_ip = `gcloud sql instances list --project=#{project_id} | grep #{instance_name} | awk '{print $5}'`.strip
39
+ Dir.chdir(SOULs.get_api_path.to_s) do
40
+ file_path = ".env"
41
+ File.open(file_path, "w") do |line|
42
+ line.write(<<~TEXT)
43
+ GOOGLE_AUTH_SUPPRESS_CREDENTIALS_WARNINGS=1
44
+ SOULS_DB_HOST=#{instance_ip}
45
+ SOULS_DB_PW=#{db_password}
46
+ SOULS_DB_USER=postgres
47
+ SOULS_GCP_PROJECT_ID=#{project_id}
48
+ SOULS_SECRET_KEY_BASE='#{SecureRandom.base64(64)}'
49
+ TZ="#{region_to_timezone(region: region)}"
50
+ TEXT
51
+ end
52
+ SOULs::Painter.create_file(file_path)
53
+ end
54
+ Dir.chdir(SOULs.get_mother_path.to_s) do
55
+ file_path = ".env.production"
56
+ File.open(file_path, "w") do |line|
57
+ line.write(<<~TEXT)
58
+ SOULS_DB_HOST="/cloudsql/#{project_id}:#{region}:#{instance_name}"
59
+ SOULS_DB_PW=#{db_password}
60
+ SOULS_DB_USER=postgres
61
+ SOULS_APP_NAME=#{app_name}
62
+ SOULS_GCP_PROJECT_ID=#{project_id}
63
+ SOULS_GCP_REGION=#{region}
64
+ SOULS_GCLOUDSQL_INSTANCE="#{project_id}:#{region}:#{instance_name}"
65
+ SOULS_SECRET_KEY_BASE='#{SecureRandom.base64(64)}'
66
+ TZ="#{region_to_timezone(region: region)}"
67
+ TEXT
68
+ end
69
+ SOULs::Painter.create_file(file_path)
70
+ end
71
+ end
72
+
60
73
  desc "list", "Show Cloud SQL Instances List"
61
74
  def list
62
75
  system("gcloud sql instances list")
@@ -111,6 +124,7 @@ module SOULs
111
124
  desc "assgin_ip", "Add Current Grobal IP to White List"
112
125
  method_option :ip, default: "", aliases: "--ip", desc: "Adding IP to Google Cloud SQL White List: e.g.'11.11.1.1'"
113
126
  def assign_ip
127
+ require(SOULs.get_mother_path.to_s + "/config/souls")
114
128
  project_id = SOULs.configuration.project_id
115
129
  instance_name = SOULs.configuration.instance_name
116
130
  ips = []
@@ -126,12 +140,15 @@ module SOULs
126
140
  -H "Authorization: Bearer "$(gcloud auth print-access-token) \
127
141
  "https://sqladmin.googleapis.com/v1/projects/#{project_id}/instances/#{instance_name}?fields=settings"`
128
142
  )
129
- unless cloud_sql["settings"]["ipConfiguration"]["authorizedNetworks"].blank?
143
+ begin
144
+ cloud_sql["settings"]["ipConfiguration"]["authorizedNetworks"].blank?
130
145
  white_ips =
131
146
  cloud_sql["settings"]["ipConfiguration"]["authorizedNetworks"].map do |sql_ips|
132
147
  sql_ips["value"]
133
148
  end
134
149
  ips = (ips + white_ips).uniq
150
+ rescue StandardError => e
151
+ puts(e)
135
152
  end
136
153
  ips = ips.join(",")
137
154
  Whirly.start(spinner: "clock", interval: 420, stop: "🎉") do
@@ -1,4 +1,3 @@
1
- require "google/cloud/pubsub"
2
1
  require_relative "./model"
3
2
  require_relative "./pubsub"
4
3
  require_relative "./conf"
@@ -10,19 +10,19 @@ module SOULs
10
10
  return false
11
11
  end
12
12
 
13
- url = `gcloud run services list |grep souls-#{project_id}-#{worker_name}| awk '{print $4}'`.strip
13
+ url = `gcloud run services list --platform=managed \
14
+ --project=#{project_id} |grep souls-#{project_id}-#{worker_name}| awk '{print $4}'`.strip
14
15
  return false if url.blank?
15
16
 
16
17
  worker_file_names = get_workers_file_paths
17
- return false if worker_file_names.blank?
18
18
 
19
- sync_pubsub_topics_and_subscriptions(workers: worker_file_names, worker_url: url)
19
+ sync_pubsub_topics_and_subscriptions(worker_file_names: worker_file_names, worker_url: url)
20
20
  SOULs::Painter.sync("All Jobs with PubSub Subscription!")
21
21
  end
22
22
 
23
23
  private
24
24
 
25
- def sync_pubsub_topics_and_subscriptions(worker_url:, workers: {})
25
+ def sync_pubsub_topics_and_subscriptions(worker_url:, worker_file_names: {})
26
26
  project_id = SOULs.configuration.project_id
27
27
  pubsub = Google::Cloud::Pubsub.new(project_id: project_id)
28
28
  topics = pubsub.topics
@@ -36,27 +36,37 @@ module SOULs
36
36
  souls_topics = topic_names.select { |n| n.include?("souls-#{worker_name}") }
37
37
 
38
38
  souls_topics.each do |name|
39
- value = workers[name.to_sym] || 0
40
- workers[name.to_sym] = value - 1
39
+ file_name = name.gsub("-", "_")
40
+ value = worker_file_names[file_name.to_sym] || 0
41
+ worker_file_names[file_name.to_sym] = value - 1
41
42
  end
42
43
 
43
- workers.each do |key, value|
44
- topic_id = key.to_s.gsub("_", "-")
45
- if value == 1
46
- create_topic(topic_id: topic_id)
47
- create_push_subscription(worker_url: worker_url, topic_id: topic_id)
44
+ if worker_file_names.blank?
45
+ return if souls_topics.blank?
46
+
47
+ souls_topics.each do |topic_id|
48
+ delete_topic(topic_id: topic_id)
49
+ delete_subscription(topic_id: topic_id)
50
+ end
51
+ else
52
+ worker_file_names.each do |key, value|
53
+ topic_id = key.to_s.gsub("_", "-")
54
+ if value == 1
55
+ create_topic(topic_id: topic_id)
56
+ create_push_subscription(worker_url: worker_url, topic_id: topic_id)
57
+ end
58
+ delete_topic(topic_id: topic_id) if value == -1
59
+ delete_subscription(topic_id: topic_id) if value == -1
48
60
  end
49
- delete_topic(topic_id: topic_id) if value == -1
50
- delete_subscription(topic_id: topic_id) if value == -1
51
61
  end
52
- workers
62
+ worker_file_names
53
63
  end
54
64
 
55
65
  def create_topic(topic_id: "worker-mailer")
56
66
  project_id = SOULs.configuration.project_id
57
67
  pubsub = Google::Cloud::Pubsub.new(project_id: project_id)
58
68
  topic = pubsub.create_topic(topic_id.to_s)
59
- puts("Topic #{topic.name} created.")
69
+ SOULs::Painter.success("Topic #{topic.name} created.")
60
70
  end
61
71
 
62
72
  def delete_topic(topic_id: "worker-mailer")
@@ -64,7 +74,7 @@ module SOULs
64
74
  pubsub = Google::Cloud::Pubsub.new(project_id: project_id)
65
75
  topic = pubsub.topic(topic_id.to_s)
66
76
  topic.delete
67
- puts("Topic #{topic_id} deleted.")
77
+ SOULs::Painter.warning("Topic #{topic_id} deleted.", "✨")
68
78
  end
69
79
 
70
80
  def delete_subscription(topic_id: "worker-mailer")
@@ -78,7 +88,7 @@ module SOULs
78
88
  def create_push_subscription(worker_url:, topic_id: "worker-mailer")
79
89
  souls_endpoint = SOULs.configuration.endpoint
80
90
  subscription_id = "#{topic_id}-sub"
81
- endpoint = "#{worker_url}/#{souls_endpoint}"
91
+ endpoint = "#{worker_url}#{souls_endpoint}"
82
92
 
83
93
  project_id = SOULs.configuration.project_id
84
94
  pubsub = Google::Cloud::Pubsub.new(project_id: project_id)
@@ -86,7 +96,7 @@ module SOULs
86
96
  topic = pubsub.topic(topic_id)
87
97
  sub = topic.subscribe(subscription_id, endpoint: endpoint, deadline: 20)
88
98
  sub.expires_in = nil
89
- puts("Push subscription #{subscription_id} created.")
99
+ SOULs::Painter.success("Push subscription #{subscription_id} created.")
90
100
  end
91
101
 
92
102
  def get_workers_file_paths
data/lib/souls/version.rb CHANGED
@@ -1,4 +1,4 @@
1
1
  module SOULs
2
- VERSION = "1.19.3".freeze
2
+ VERSION = "1.19.7".freeze
3
3
  public_constant :VERSION
4
4
  end
@@ -1 +1 @@
1
- 1.19.3
1
+ 1.19.7
@@ -1 +1 @@
1
- 1.19.3
1
+ 1.19.7
data/lib/souls.rb CHANGED
@@ -9,6 +9,7 @@ require "whirly"
9
9
  require "tty-prompt"
10
10
  require "thor"
11
11
  require "resolv"
12
+ require "google/cloud/pubsub"
12
13
 
13
14
  module SOULs
14
15
  extend SOULs::Utils
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: souls
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.19.3
4
+ version: 1.19.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - POPPIN-FUMI
@@ -124,6 +124,20 @@ dependencies:
124
124
  - - ">="
125
125
  - !ruby/object:Gem::Version
126
126
  version: 0.3.0
127
+ - !ruby/object:Gem::Dependency
128
+ name: httpclient
129
+ requirement: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: 2.8.3
134
+ type: :runtime
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: 2.8.3
127
141
  - !ruby/object:Gem::Dependency
128
142
  name: thor
129
143
  requirement: !ruby/object:Gem::Requirement