souls 0.23.5 → 0.23.9
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 +4 -4
- data/.rubocop.yml +73 -138
- data/Gemfile.lock +1 -1
- data/README.md +23 -11
- data/Rakefile +2 -2
- data/config/souls.rb +1 -1
- data/exe/souls +89 -73
- data/lib/souls.rb +157 -144
- data/lib/souls/gcloud.rb +1 -0
- data/lib/souls/gcloud/compute.rb +44 -32
- data/lib/souls/gcloud/iam.rb +9 -9
- data/lib/souls/gcloud/pubsub.rb +21 -0
- data/lib/souls/generate/application.rb +160 -160
- data/lib/souls/generate/connection.rb +13 -15
- data/lib/souls/generate/edge.rb +13 -15
- data/lib/souls/generate/model.rb +16 -17
- data/lib/souls/generate/mutation.rb +225 -221
- data/lib/souls/generate/policy.rb +44 -45
- data/lib/souls/generate/query.rb +49 -49
- data/lib/souls/generate/resolver.rb +121 -124
- data/lib/souls/generate/rspec_factory.rb +49 -52
- data/lib/souls/generate/rspec_model.rb +17 -18
- data/lib/souls/generate/rspec_mutation.rb +193 -199
- data/lib/souls/generate/rspec_policy.rb +38 -39
- data/lib/souls/generate/rspec_query.rb +133 -140
- data/lib/souls/generate/rspec_resolver.rb +147 -154
- data/lib/souls/generate/type.rb +34 -25
- data/lib/souls/init.rb +51 -50
- data/lib/souls/version.rb +2 -1
- data/souls.gemspec +12 -7
- metadata +7 -6
data/lib/souls.rb
CHANGED
@@ -10,162 +10,174 @@ require "paint"
|
|
10
10
|
require "whirly"
|
11
11
|
|
12
12
|
module Souls
|
13
|
-
SOULS_METHODS = [
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
]
|
13
|
+
SOULS_METHODS = %w[
|
14
|
+
model
|
15
|
+
query
|
16
|
+
mutation
|
17
|
+
type
|
18
|
+
resolver
|
19
|
+
policy
|
20
|
+
rspec_factory
|
21
|
+
rspec_model
|
22
|
+
rspec_query
|
23
|
+
rspec_mutation
|
24
|
+
rspec_resolver
|
25
|
+
rspec_policy
|
26
|
+
].freeze
|
27
|
+
public_constant :SOULS_METHODS
|
27
28
|
class Error < StandardError; end
|
28
|
-
|
29
|
-
|
29
|
+
class << self
|
30
|
+
attr_accessor :configuration
|
31
|
+
end
|
30
32
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
33
|
+
def self.run_psql
|
34
|
+
system(
|
35
|
+
"docker run --rm -d \
|
36
|
+
-p 5433:5432 \
|
37
|
+
-v postgres-tmp:/var/lib/postgresql/data \
|
38
|
+
-e POSTGRES_USER=postgres \
|
39
|
+
-e POSTGRES_PASSWORD=postgres \
|
40
|
+
-e POSTGRES_DB=souls_test \
|
41
|
+
postgres:13-alpine"
|
42
|
+
)
|
43
|
+
system("docker ps")
|
44
|
+
end
|
41
45
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
46
|
+
def self.run_mysql
|
47
|
+
system(
|
48
|
+
"docker run --rm -d \
|
49
|
+
-p 3306:3306 \
|
50
|
+
-v mysql-tmp:/var/lib/mysql \
|
51
|
+
-e MYSQL_USER=mysql \
|
52
|
+
-e MYSQL_ROOT_PASSWORD=mysql \
|
53
|
+
-e MYSQL_DB=souls_test \
|
54
|
+
mysql:latest"
|
55
|
+
)
|
56
|
+
system("docker ps")
|
57
|
+
end
|
52
58
|
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
59
|
+
def self.run_awake(url)
|
60
|
+
app = Souls.configuration.app
|
61
|
+
system(
|
62
|
+
"gcloud scheduler jobs create http #{app}-awake
|
63
|
+
--schedule '0,10,20,30,40,50 * * * *' --uri #{url} --http-method GET"
|
64
|
+
)
|
65
|
+
end
|
57
66
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
end
|
69
|
-
yield.tap do
|
70
|
-
iter = false
|
71
|
-
spinner.join
|
67
|
+
def self.show_wait_spinner(fps = 10)
|
68
|
+
chars = %w[| / - \\]
|
69
|
+
delay = 1.0 / fps
|
70
|
+
iter = 0
|
71
|
+
spinner =
|
72
|
+
Thread.new do
|
73
|
+
while iter
|
74
|
+
print(chars[(iter += 1) % chars.length])
|
75
|
+
sleep(delay)
|
76
|
+
print("\b")
|
72
77
|
end
|
73
78
|
end
|
79
|
+
yield.tap do
|
80
|
+
iter = false
|
81
|
+
spinner.join
|
82
|
+
end
|
83
|
+
end
|
74
84
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
{
|
101
|
-
gems: updated_gems,
|
102
|
-
lines: updated_lines,
|
103
|
-
updated_gem_versions: updated_gem_versions
|
104
|
-
}
|
85
|
+
def self.gemfile_latest_version
|
86
|
+
file_path = "./Gemfile"
|
87
|
+
updated_gems = []
|
88
|
+
updated_gem_versions = []
|
89
|
+
updated_lines = []
|
90
|
+
from_dev = false
|
91
|
+
File.open(file_path, "r") do |f|
|
92
|
+
f.each_line do |line|
|
93
|
+
from_dev = true if line.include?("group")
|
94
|
+
next unless line.include?("gem ")
|
95
|
+
|
96
|
+
gem = line.gsub("gem ", "").gsub("\"", "").gsub("\n", "").gsub(" ", "").split(",")
|
97
|
+
url = URI("https://rubygems.org/api/v1/versions/#{gem[0]}/latest.json")
|
98
|
+
res = Net::HTTP.get_response(url)
|
99
|
+
data = JSON.parse(res.body)
|
100
|
+
next if data["version"].to_s == gem[1].to_s
|
101
|
+
|
102
|
+
updated_lines << if from_dev
|
103
|
+
" gem \"#{gem[0]}\", \"#{data['version']}\""
|
104
|
+
else
|
105
|
+
"gem \"#{gem[0]}\", \"#{data['version']}\""
|
106
|
+
end
|
107
|
+
updated_gems << (gem[0]).to_s
|
108
|
+
updated_gem_versions << data["version"]
|
109
|
+
system("gem update #{gem[0]}")
|
105
110
|
end
|
111
|
+
end
|
112
|
+
{
|
113
|
+
gems: updated_gems,
|
114
|
+
lines: updated_lines,
|
115
|
+
updated_gem_versions: updated_gem_versions
|
116
|
+
}
|
117
|
+
end
|
106
118
|
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
-
new_line.write "#{new_gems[:lines][@i]}\n"
|
151
|
-
@i += 1
|
152
|
-
else
|
153
|
-
new_line.write line
|
154
|
-
end
|
119
|
+
def self.update_gemfile
|
120
|
+
file_path = "./Gemfile"
|
121
|
+
tmp_file = "./tmp/Gemfile"
|
122
|
+
new_gems = gemfile_latest_version
|
123
|
+
logs = []
|
124
|
+
message = Paint["\nAlready Up to date!", :green]
|
125
|
+
return "Already Up to date!" && puts(message) if new_gems[:gems].blank?
|
126
|
+
|
127
|
+
@i = 0
|
128
|
+
File.open(file_path, "r") do |f|
|
129
|
+
File.open(tmp_file, "w") do |new_line|
|
130
|
+
f.each_line do |line|
|
131
|
+
gem = line.gsub("gem ", "").gsub("\"", "").gsub("\n", "").gsub(" ", "").split(",")
|
132
|
+
if new_gems[:gems].include?(gem[0])
|
133
|
+
old_ver = gem[1].split(".")
|
134
|
+
new_ver = new_gems[:updated_gem_versions][@i].split(".")
|
135
|
+
if old_ver[0] < new_ver[0]
|
136
|
+
logs << Paint % [
|
137
|
+
"#{gem[0]} v#{gem[1]} → %{red_text}",
|
138
|
+
:white,
|
139
|
+
{
|
140
|
+
red_text: ["v#{new_gems[:updated_gem_versions][@i]}", :red]
|
141
|
+
}
|
142
|
+
]
|
143
|
+
elsif old_ver[1] < new_ver[1]
|
144
|
+
logs << Paint % [
|
145
|
+
"#{gem[0]} v#{gem[1]} → v#{new_ver[0]}.%{yellow_text}",
|
146
|
+
:white,
|
147
|
+
{
|
148
|
+
yellow_text: ["#{new_ver[1]}.#{new_ver[2]}", :yellow]
|
149
|
+
}
|
150
|
+
]
|
151
|
+
elsif old_ver[2] < new_ver[2]
|
152
|
+
logs << Paint % [
|
153
|
+
"#{gem[0]} v#{gem[1]} → v#{new_ver[0]}.#{new_ver[1]}.%{green_text}",
|
154
|
+
:white,
|
155
|
+
{
|
156
|
+
green_text: [(new_ver[2]).to_s, :green]
|
157
|
+
}
|
158
|
+
]
|
159
|
+
end
|
160
|
+
if gem[0] == "souls"
|
161
|
+
logs << Paint % ["\nSOULs Doc: %{cyan_text}", :white, { cyan_text: ["https://souls.elsoul.nl\n", :cyan] }]
|
155
162
|
end
|
163
|
+
new_line.write("#{new_gems[:lines][@i]}\n")
|
164
|
+
@i += 1
|
165
|
+
else
|
166
|
+
new_line.write(line)
|
156
167
|
end
|
157
168
|
end
|
158
|
-
FileUtils.rm "./Gemfile"
|
159
|
-
FileUtils.rm "./Gemfile.lock"
|
160
|
-
FileUtils.mv "./tmp/Gemfile", "./Gemfile"
|
161
|
-
system "bundle update"
|
162
|
-
success = Paint["\n\nSuccessfully Updated These Gems!\n", :green]
|
163
|
-
puts success
|
164
|
-
logs.each do |line|
|
165
|
-
puts line
|
166
|
-
end
|
167
169
|
end
|
168
170
|
end
|
171
|
+
FileUtils.rm("./Gemfile")
|
172
|
+
FileUtils.rm("./Gemfile.lock")
|
173
|
+
FileUtils.mv("./tmp/Gemfile", "./Gemfile")
|
174
|
+
system("bundle update")
|
175
|
+
success = Paint["\n\nSuccessfully Updated These Gems!\n", :green]
|
176
|
+
puts(success)
|
177
|
+
logs.each do |line|
|
178
|
+
puts(line)
|
179
|
+
end
|
180
|
+
end
|
169
181
|
|
170
182
|
def self.configure
|
171
183
|
self.configuration ||= Configuration.new
|
@@ -173,14 +185,15 @@ module Souls
|
|
173
185
|
end
|
174
186
|
|
175
187
|
class Configuration
|
176
|
-
attr_accessor :app, :strain, :project_id, :
|
188
|
+
attr_accessor :app, :strain, :project_id, :worker_repo, :api_repo, :worker_endpoint
|
177
189
|
|
178
190
|
def initialize
|
179
191
|
@app = nil
|
180
192
|
@project_id = nil
|
181
193
|
@strain = nil
|
182
|
-
@
|
183
|
-
@
|
194
|
+
@worker_repo = nil
|
195
|
+
@api_repo = nil
|
196
|
+
@worker_endpoint = nil
|
184
197
|
end
|
185
198
|
end
|
186
199
|
end
|
data/lib/souls/gcloud.rb
CHANGED
data/lib/souls/gcloud/compute.rb
CHANGED
@@ -3,58 +3,70 @@ module Souls
|
|
3
3
|
class << self
|
4
4
|
def auth_login
|
5
5
|
project_id = Souls.configuration.project_id
|
6
|
-
system
|
7
|
-
system
|
6
|
+
system("gcloud config set project #{project_id}")
|
7
|
+
system("gcloud auth login")
|
8
8
|
end
|
9
9
|
|
10
10
|
def enable_permissions
|
11
|
-
system
|
12
|
-
puts
|
13
|
-
system
|
14
|
-
puts
|
15
|
-
system
|
16
|
-
puts
|
17
|
-
system
|
18
|
-
puts
|
19
|
-
system
|
20
|
-
puts
|
21
|
-
system
|
22
|
-
puts
|
23
|
-
system
|
24
|
-
puts
|
25
|
-
system
|
26
|
-
puts
|
11
|
+
system("gcloud services enable compute.googleapis.com")
|
12
|
+
puts("Operating permission to compute.googleapis.com ...")
|
13
|
+
system("gcloud services enable iam.googleapis.com")
|
14
|
+
puts("Operating permission to iam.googleapis.com ...")
|
15
|
+
system("gcloud services enable dns.googleapis.com")
|
16
|
+
puts("Operating permission to dns.googleapis.com ...")
|
17
|
+
system("gcloud services enable sqladmin.googleapis.com")
|
18
|
+
puts("Operating permission to sqladmin.googleapis.com ...")
|
19
|
+
system("gcloud services enable sql-component.googleapis.com")
|
20
|
+
puts("Operating permission to sql-component.googleapis.com ...")
|
21
|
+
system("gcloud services enable servicenetworking.googleapis.com")
|
22
|
+
puts("Operating permission to servicenetworking.googleapis.com ...")
|
23
|
+
system("gcloud services enable containerregistry.googleapis.com")
|
24
|
+
puts("Operating permission to containerregistry.googleapis.com")
|
25
|
+
system("gcloud services enable run.googleapis.com")
|
26
|
+
puts("Operating permission to run.googleapis.com")
|
27
27
|
end
|
28
28
|
|
29
29
|
def create_network
|
30
30
|
return "Error: Please Set Souls.configuration" if Souls.configuration.app.nil?
|
31
|
+
|
31
32
|
network = Souls.configuration.app
|
32
|
-
system
|
33
|
+
system("gcloud compute networks create #{network}")
|
33
34
|
rescue StandardError => e
|
34
|
-
raise
|
35
|
+
raise(StandardError, e)
|
35
36
|
end
|
36
37
|
|
37
|
-
def create_firewall
|
38
|
+
def create_firewall(ip_range: "10.140.0.0/20")
|
38
39
|
network = Souls.configuration.app
|
39
|
-
system
|
40
|
-
|
40
|
+
system(
|
41
|
+
"gcloud compute firewall-rules create #{network}
|
42
|
+
--network #{network}
|
43
|
+
--allow tcp,udp,icmp
|
44
|
+
--source-ranges #{ip_range}"
|
45
|
+
)
|
46
|
+
system("gcloud compute firewall-rules create #{network}-ssh --network #{network} --allow tcp:22,tcp:3389,icmp")
|
41
47
|
end
|
42
48
|
|
43
49
|
def create_private_access
|
44
50
|
network = Souls.configuration.app
|
45
51
|
project_id = Souls.configuration.project_id
|
46
|
-
system
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
52
|
+
system(
|
53
|
+
"gcloud compute addresses create #{network}-my-network \
|
54
|
+
--global \
|
55
|
+
--purpose=VPC_PEERING \
|
56
|
+
--prefix-length=16 \
|
57
|
+
--description='peering range for SOULs' \
|
58
|
+
--network=#{network} \
|
59
|
+
--project=#{project_id}"
|
60
|
+
)
|
53
61
|
end
|
54
62
|
|
55
|
-
def create_sql_instance
|
63
|
+
def create_sql_instance(root_pass: "Postgre123!", zone: "asia-northeast1-b")
|
56
64
|
app = "#{Souls.configuration.app}-db"
|
57
|
-
system
|
65
|
+
system(
|
66
|
+
"gcloud sql instances create #{app}
|
67
|
+
--database-version=POSTGRES_13 --cpu=2 --memory=7680MB --zone=#{zone}
|
68
|
+
--root-password='#{root_pass}' --database-flags cloudsql.iam_authentication=on"
|
69
|
+
)
|
58
70
|
end
|
59
71
|
end
|
60
72
|
end
|
data/lib/souls/gcloud/iam.rb
CHANGED
@@ -1,31 +1,31 @@
|
|
1
1
|
module Souls
|
2
2
|
module Gcloud
|
3
3
|
class << self
|
4
|
-
def create_service_account
|
4
|
+
def create_service_account(service_account: "souls-app")
|
5
5
|
`gcloud iam service-accounts create #{service_account} \
|
6
6
|
--description="Souls Service Account" \
|
7
7
|
--display-name="#{service_account}"`
|
8
8
|
end
|
9
9
|
|
10
|
-
def create_service_account_key
|
10
|
+
def create_service_account_key(service_account: "souls-app")
|
11
11
|
project_id = Souls.configuration.project_id
|
12
12
|
`gcloud iam service-accounts keys create ./config/keyfile.json \
|
13
13
|
--iam-account #{service_account}@#{project_id}.iam.gserviceaccount.com`
|
14
14
|
end
|
15
15
|
|
16
|
-
def add_service_account_role
|
16
|
+
def add_service_account_role(service_account: "souls-app", role: "roles/firebase.admin")
|
17
17
|
project_id = Souls.configuration.project_id
|
18
18
|
`gcloud projects add-iam-policy-binding #{project_id} \
|
19
19
|
--member="serviceAccount:#{service_account}@#{project_id}.iam.gserviceaccount.com" \
|
20
20
|
--role="#{role}"`
|
21
21
|
end
|
22
22
|
|
23
|
-
def add_permissions
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
23
|
+
def add_permissions(service_account: "souls-app")
|
24
|
+
add_service_account_role(service_account: service_account, role: "roles/cloudsql.serviceAgent")
|
25
|
+
add_service_account_role(service_account: service_account, role: "roles/containerregistry.ServiceAgent")
|
26
|
+
add_service_account_role(service_account: service_account, role: "roles/pubsub.serviceAgent")
|
27
|
+
add_service_account_role(service_account: service_account, role: "roles/firestore.serviceAgent")
|
28
|
+
add_service_account_role(service_account: service_account, role: "roles/iam.serviceAccountUser")
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|