souls 0.23.4 → 0.23.8
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 -135
- data/Gemfile.lock +1 -1
- data/README.md +23 -11
- data/Rakefile +2 -2
- data/exe/souls +74 -73
- data/lib/souls.rb +153 -141
- data/lib/souls/gcloud/compute.rb +61 -51
- data/lib/souls/gcloud/iam.rb +22 -24
- 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 +6 -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
|
data/lib/souls/gcloud/compute.rb
CHANGED
@@ -1,61 +1,71 @@
|
|
1
1
|
module Souls
|
2
2
|
module Gcloud
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
3
|
+
def self.auth_login
|
4
|
+
project_id = Souls.configuration.project_id
|
5
|
+
system("gcloud config set project #{project_id}")
|
6
|
+
system("gcloud auth login")
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.enable_permissions
|
10
|
+
system("gcloud services enable compute.googleapis.com")
|
11
|
+
puts("Operating permission to compute.googleapis.com ...")
|
12
|
+
system("gcloud services enable iam.googleapis.com")
|
13
|
+
puts("Operating permission to iam.googleapis.com ...")
|
14
|
+
system("gcloud services enable dns.googleapis.com")
|
15
|
+
puts("Operating permission to dns.googleapis.com ...")
|
16
|
+
system("gcloud services enable sqladmin.googleapis.com")
|
17
|
+
puts("Operating permission to sqladmin.googleapis.com ...")
|
18
|
+
system("gcloud services enable sql-component.googleapis.com")
|
19
|
+
puts("Operating permission to sql-component.googleapis.com ...")
|
20
|
+
system("gcloud services enable servicenetworking.googleapis.com")
|
21
|
+
puts("Operating permission to servicenetworking.googleapis.com ...")
|
22
|
+
system("gcloud services enable containerregistry.googleapis.com")
|
23
|
+
puts("Operating permission to containerregistry.googleapis.com")
|
24
|
+
system("gcloud services enable run.googleapis.com")
|
25
|
+
puts("Operating permission to run.googleapis.com")
|
26
|
+
end
|
9
27
|
|
10
|
-
|
11
|
-
|
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
|
-
end
|
28
|
+
def self.create_network
|
29
|
+
return "Error: Please Set Souls.configuration" if Souls.configuration.app.nil?
|
28
30
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
raise StandardError, e
|
35
|
-
end
|
31
|
+
network = Souls.configuration.app
|
32
|
+
system("gcloud compute networks create #{network}")
|
33
|
+
rescue StandardError => e
|
34
|
+
raise(StandardError, e)
|
35
|
+
end
|
36
36
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
37
|
+
def self.create_firewall(ip_range: "10.140.0.0/20")
|
38
|
+
network = Souls.configuration.app
|
39
|
+
system(
|
40
|
+
"gcloud compute firewall-rules create #{network}
|
41
|
+
--network #{network}
|
42
|
+
--allow tcp,udp,icmp
|
43
|
+
--source-ranges #{ip_range}"
|
44
|
+
)
|
45
|
+
system("gcloud compute firewall-rules create #{network}-ssh --network #{network} --allow tcp:22,tcp:3389,icmp")
|
46
|
+
end
|
42
47
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
48
|
+
def self.create_private_access
|
49
|
+
network = Souls.configuration.app
|
50
|
+
project_id = Souls.configuration.project_id
|
51
|
+
system(
|
52
|
+
"gcloud compute addresses create #{network}-my-network \
|
53
|
+
--global \
|
54
|
+
--purpose=VPC_PEERING \
|
55
|
+
--prefix-length=16 \
|
56
|
+
--description='peering range for SOULs' \
|
57
|
+
--network=#{network} \
|
58
|
+
--project=#{project_id}"
|
59
|
+
)
|
60
|
+
end
|
54
61
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
62
|
+
def self.create_sql_instance(root_pass: "Postgre123!", zone: "asia-northeast1-b")
|
63
|
+
app = "#{Souls.configuration.app}-db"
|
64
|
+
system(
|
65
|
+
"gcloud sql instances create #{app}
|
66
|
+
--database-version=POSTGRES_13 --cpu=2 --memory=7680MB --zone=#{zone}
|
67
|
+
--root-password='#{root_pass}' --database-flags cloudsql.iam_authentication=on"
|
68
|
+
)
|
59
69
|
end
|
60
70
|
end
|
61
71
|
end
|
data/lib/souls/gcloud/iam.rb
CHANGED
@@ -1,32 +1,30 @@
|
|
1
1
|
module Souls
|
2
2
|
module Gcloud
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
end
|
3
|
+
def self.create_service_account(service_account: "souls-app")
|
4
|
+
`gcloud iam service-accounts create #{service_account} \
|
5
|
+
--description="Souls Service Account" \
|
6
|
+
--display-name="#{service_account}"`
|
7
|
+
end
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
9
|
+
def self.create_service_account_key(service_account: "souls-app")
|
10
|
+
project_id = Souls.configuration.project_id
|
11
|
+
`gcloud iam service-accounts keys create ./config/keyfile.json \
|
12
|
+
--iam-account #{service_account}@#{project_id}.iam.gserviceaccount.com`
|
13
|
+
end
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
15
|
+
def self.add_service_account_role(service_account: "souls-app", role: "roles/firebase.admin")
|
16
|
+
project_id = Souls.configuration.project_id
|
17
|
+
`gcloud projects add-iam-policy-binding #{project_id} \
|
18
|
+
--member="serviceAccount:#{service_account}@#{project_id}.iam.gserviceaccount.com" \
|
19
|
+
--role="#{role}"`
|
20
|
+
end
|
22
21
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end
|
22
|
+
def self.add_permissions(service_account: "souls-app")
|
23
|
+
add_service_account_role(service_account: service_account, role: "roles/cloudsql.serviceAgent")
|
24
|
+
add_service_account_role(service_account: service_account, role: "roles/containerregistry.ServiceAgent")
|
25
|
+
add_service_account_role(service_account: service_account, role: "roles/pubsub.serviceAgent")
|
26
|
+
add_service_account_role(service_account: service_account, role: "roles/firestore.serviceAgent")
|
27
|
+
add_service_account_role(service_account: service_account, role: "roles/iam.serviceAccountUser")
|
30
28
|
end
|
31
29
|
end
|
32
30
|
end
|