altaire-siren 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +10 -0
  3. data/Gemfile +4 -0
  4. data/Gemfile.lock +77 -0
  5. data/LICENSE.txt +21 -0
  6. data/README.md +39 -0
  7. data/Rakefile +2 -0
  8. data/altaire-siren.gemspec +32 -0
  9. data/bin/console +14 -0
  10. data/bin/setup +8 -0
  11. data/docs/docs/commands/crypto.md +25 -0
  12. data/docs/docs/commands/song.md +59 -0
  13. data/docs/docs/index.md +0 -0
  14. data/docs/mkdocs.yml +20 -0
  15. data/docs/serve.sh +1 -0
  16. data/docs/site/404.html +313 -0
  17. data/docs/site/assets/fonts/font-awesome.css +4 -0
  18. data/docs/site/assets/fonts/material-icons.css +13 -0
  19. data/docs/site/assets/fonts/specimen/FontAwesome.ttf +0 -0
  20. data/docs/site/assets/fonts/specimen/FontAwesome.woff +0 -0
  21. data/docs/site/assets/fonts/specimen/FontAwesome.woff2 +0 -0
  22. data/docs/site/assets/fonts/specimen/MaterialIcons-Regular.ttf +0 -0
  23. data/docs/site/assets/fonts/specimen/MaterialIcons-Regular.woff +0 -0
  24. data/docs/site/assets/fonts/specimen/MaterialIcons-Regular.woff2 +0 -0
  25. data/docs/site/assets/images/favicon.png +0 -0
  26. data/docs/site/assets/images/icons/bitbucket.1b09e088.svg +1 -0
  27. data/docs/site/assets/images/icons/github.f0b8504a.svg +1 -0
  28. data/docs/site/assets/images/icons/gitlab.6dd19c00.svg +1 -0
  29. data/docs/site/assets/javascripts/application.c648116f.js +6 -0
  30. data/docs/site/assets/javascripts/lunr/lunr.da.js +1 -0
  31. data/docs/site/assets/javascripts/lunr/lunr.de.js +1 -0
  32. data/docs/site/assets/javascripts/lunr/lunr.du.js +1 -0
  33. data/docs/site/assets/javascripts/lunr/lunr.es.js +1 -0
  34. data/docs/site/assets/javascripts/lunr/lunr.fi.js +1 -0
  35. data/docs/site/assets/javascripts/lunr/lunr.fr.js +1 -0
  36. data/docs/site/assets/javascripts/lunr/lunr.hu.js +1 -0
  37. data/docs/site/assets/javascripts/lunr/lunr.it.js +1 -0
  38. data/docs/site/assets/javascripts/lunr/lunr.ja.js +1 -0
  39. data/docs/site/assets/javascripts/lunr/lunr.jp.js +1 -0
  40. data/docs/site/assets/javascripts/lunr/lunr.multi.js +1 -0
  41. data/docs/site/assets/javascripts/lunr/lunr.nl.js +1 -0
  42. data/docs/site/assets/javascripts/lunr/lunr.no.js +1 -0
  43. data/docs/site/assets/javascripts/lunr/lunr.pt.js +1 -0
  44. data/docs/site/assets/javascripts/lunr/lunr.ro.js +1 -0
  45. data/docs/site/assets/javascripts/lunr/lunr.ru.js +1 -0
  46. data/docs/site/assets/javascripts/lunr/lunr.stemmer.support.js +1 -0
  47. data/docs/site/assets/javascripts/lunr/lunr.sv.js +1 -0
  48. data/docs/site/assets/javascripts/lunr/lunr.th.js +1 -0
  49. data/docs/site/assets/javascripts/lunr/lunr.tr.js +1 -0
  50. data/docs/site/assets/javascripts/lunr/tinyseg.js +1 -0
  51. data/docs/site/assets/javascripts/lunr/wordcut.js +1 -0
  52. data/docs/site/assets/javascripts/modernizr.74668098.js +1 -0
  53. data/docs/site/assets/stylesheets/application-palette.a8b3c06d.css +1 -0
  54. data/docs/site/assets/stylesheets/application.30686662.css +1 -0
  55. data/docs/site/commands/crypto/index.html +470 -0
  56. data/docs/site/commands/song/index.html +474 -0
  57. data/docs/site/index.html +348 -0
  58. data/docs/site/search/search_index.json +1 -0
  59. data/docs/site/sitemap.xml +18 -0
  60. data/docs/site/sitemap.xml.gz +0 -0
  61. data/exe/siren +5 -0
  62. data/lib/siren.rb +9 -0
  63. data/lib/siren/cli.rb +83 -0
  64. data/lib/siren/crypto.rb +17 -0
  65. data/lib/siren/song.rb +214 -0
  66. data/lib/siren/stack.rb +25 -0
  67. data/lib/siren/version.rb +3 -0
  68. data/public.jwk +1 -0
  69. metadata +210 -0
@@ -0,0 +1,17 @@
1
+ require "jose"
2
+
3
+ module Siren
4
+ module Crypto
5
+
6
+ def self.genkeys
7
+ key = JOSE::JWK.generate_key([:ec, "P-256"])
8
+ return [key, key.to_public]
9
+ end
10
+
11
+ def self.encrypt (data)
12
+ @key ||= JOSE::JWK.from_file("public.jwk")
13
+ @key.box_encrypt(data)[0].compact
14
+ end
15
+
16
+ end
17
+ end
@@ -0,0 +1,214 @@
1
+ require 'yaml'
2
+
3
+ module Siren
4
+
5
+ class Song
6
+
7
+ attr_reader :env, :services
8
+
9
+ def self.load (filename)
10
+ new(YAML.load(File.read(filename)))
11
+ end
12
+
13
+ def initialize (data)
14
+ @name = data["metadata"]["name"]
15
+ @ns = data["metadata"]["namespace"]
16
+ @spec = data["spec"]
17
+ process()
18
+ end
19
+
20
+ def get (what, key)
21
+ return [] unless what.has_key?(key)
22
+ val = what[key]
23
+ return val if val.is_a?(Array)
24
+ return [val]
25
+ end
26
+
27
+ def process ()
28
+ @env = {}
29
+ @env.merge! process_env(@spec["env"])
30
+ @services = get(@spec, "service").map do |svc|
31
+ svc
32
+ end
33
+ end
34
+
35
+ def process_env (hash)
36
+ hash = hash.dup
37
+ hash.map do |name, value|
38
+ next unless value.is_a?(Hash)
39
+ case value.keys[0]
40
+ when "encrypt"
41
+ hash[name] = { "secure" => Siren::Crypto.encrypt(value.values[0]) }
42
+ end
43
+ end
44
+ return hash
45
+ end
46
+
47
+ def to_yaml
48
+ data = {
49
+ "apiVersion" => "altaire.com/v1alpha1",
50
+ "kind" => "Song",
51
+ "metadata" => { "name" => @name, "namespace" => @ns }.compact,
52
+ "spec" => {
53
+ "services" => @services,
54
+ "env" => @env,
55
+ }
56
+ }
57
+ JSON.parse(data.to_json).to_yaml
58
+ end
59
+
60
+ def makename (*parts)
61
+ parts.compact.join("-")
62
+ end
63
+
64
+ def env_to_k8s (hash)
65
+ res = []
66
+ hash.each do |name, value|
67
+ res << { name: name, value: value }
68
+ end
69
+ res
70
+ end
71
+
72
+ def to_deployment (svc)
73
+ name = makename(@name, svc["name"])
74
+ @stack.things << {
75
+ apiVersion: "apps/v1",
76
+ kind: "Deployment",
77
+ metadata: { name: name, "namespace" => @ns }.compact,
78
+ spec: {
79
+ selector: {
80
+ matchLabels: {
81
+ service: name
82
+ }
83
+ },
84
+ template: {
85
+ metadata: {
86
+ labels: {
87
+ service: name
88
+ }
89
+ },
90
+ spec: {
91
+ containers: [
92
+ name: name,
93
+ image: svc["image"],
94
+ env: env_to_k8s(env.merge(svc["env"] || {})),
95
+ ],
96
+ imagePullSecrets: [{ name: "regcred" }],
97
+ }
98
+ },
99
+ },
100
+ }
101
+ end
102
+
103
+ def to_service (svc)
104
+ name = makename(@name, svc["name"])
105
+ @stack.things << {
106
+ apiVersion: "v1",
107
+ kind: "Service",
108
+ metadata: { name: name, "namespace" => @ns }.compact,
109
+ spec: {
110
+ selector: {
111
+ service: name
112
+ },
113
+ ports: get(svc, "publish").map do |publish|
114
+ {
115
+ targetPort: publish["port"],
116
+ port: publish["externalPort"] || 80,
117
+ }
118
+ end
119
+ },
120
+ }
121
+ end
122
+
123
+ def to_certificate (svc)
124
+ name = makename(@name, svc["name"])
125
+ get(svc, "publish").map do |publish|
126
+ get(publish, "domain").map do |domain|
127
+ @stack.things << {
128
+ apiVersion: "cert-manager.io/v1alpha2",
129
+ kind: "Certificate",
130
+ metadata: { name: name, "namespace" => @ns }.compact,
131
+ spec: {
132
+ secretName: makename(name, domain, "tls"),
133
+ duration: "2160h",
134
+ renewBefore: "360h",
135
+ commonName: domain,
136
+ dnsNames: [domain],
137
+ issuerRef: {kind: "ClusterIssuer", name: "letsencrypt-production"},
138
+ },
139
+ }
140
+ end
141
+ end
142
+ end
143
+
144
+ def to_domain (svc)
145
+ name = makename(@name, svc["name"])
146
+ get(svc, "publish").map do |publish|
147
+ get(publish, "domain").map do |domain|
148
+ @stack.things << {
149
+ apiVersion: "altaire.com/v1alpha1",
150
+ kind: "Domain",
151
+ metadata: { name: makename(name, domain), "namespace" => @ns }.compact,
152
+ spec: {
153
+ domain: domain,
154
+ service: "traefik",
155
+ }
156
+ }
157
+ end
158
+ end
159
+ end
160
+
161
+ def to_ingress_route (svc)
162
+ name = makename(@name, svc["name"])
163
+ get(svc, "publish").map do |publish|
164
+ get(publish, "domain").map do |domain|
165
+ @stack.things << {
166
+ apiVersion: "traefik.containo.us/v1alpha1",
167
+ kind: "IngressRoute",
168
+ metadata: { name: makename(name, domain), "namespace" => @ns }.compact,
169
+ spec: {
170
+ tls: { secretName: makename(name, domain, "tls") },
171
+ routes: [
172
+ {
173
+ match: "Host(`#{domain}`)",
174
+ kind: "Rule",
175
+ services: [
176
+ {
177
+ name: name,
178
+ port: 80,
179
+ }
180
+ ],
181
+ middlewares: publish["auth"] ? [{name: "altaire-auth"}] : []
182
+ }
183
+ ]
184
+ }
185
+ }
186
+ end
187
+ end
188
+ end
189
+
190
+ def to_namespace ()
191
+ return if @ns == nil
192
+ @stack.things << {
193
+ apiVersion: "v1",
194
+ kind: "Namespace",
195
+ metadata: { name: @ns },
196
+ }
197
+ end
198
+
199
+ def to_stack ()
200
+ @stack = Stack.new
201
+ to_namespace()
202
+ @services.each do |svc|
203
+ to_deployment(svc)
204
+ to_service(svc)
205
+ to_certificate(svc)
206
+ to_domain(svc)
207
+ to_ingress_route(svc)
208
+ end
209
+ @stack
210
+ end
211
+
212
+ end
213
+
214
+ end
@@ -0,0 +1,25 @@
1
+ require 'yaml'
2
+
3
+ module Siren
4
+
5
+ class Stack
6
+
7
+ attr_reader :things
8
+
9
+ def self.load (filename)
10
+ new(YAML.load(File.read(filename)))
11
+ end
12
+
13
+ def initialize ()
14
+ @things = []
15
+ end
16
+
17
+ def to_yaml ()
18
+ @things.map do |thing|
19
+ JSON.parse(thing.to_json).to_yaml
20
+ end.join
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,3 @@
1
+ module Siren
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1 @@
1
+ {"crv":"P-256","d":"R72pkR_p0WwCfhIU2qaxMWgrLEDWJt-CQuYo5jLzSmM","kty":"EC","x":"jP-5eOdnFX4bI4ofoyhNhq7kEzhnFk1lAKQCBFQwY1A","y":"ga7qwkwBMopCGZoOP7awn4WD5fL_Dn_n9QuyQjr2XZQ"}
metadata ADDED
@@ -0,0 +1,210 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: altaire-siren
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Nathan Baum
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-10-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: jose
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.1.3
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.1.3
27
+ - !ruby/object:Gem::Dependency
28
+ name: clamp
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '='
32
+ - !ruby/object:Gem::Version
33
+ version: 1.3.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '='
39
+ - !ruby/object:Gem::Version
40
+ version: 1.3.1
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.2'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.2'
83
+ - !ruby/object:Gem::Dependency
84
+ name: cucumber
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: aruba
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description:
112
+ email:
113
+ - nathan@altaire.com
114
+ executables:
115
+ - siren
116
+ extensions: []
117
+ extra_rdoc_files: []
118
+ files:
119
+ - ".gitignore"
120
+ - Gemfile
121
+ - Gemfile.lock
122
+ - LICENSE.txt
123
+ - README.md
124
+ - Rakefile
125
+ - altaire-siren.gemspec
126
+ - bin/console
127
+ - bin/setup
128
+ - docs/docs/commands/crypto.md
129
+ - docs/docs/commands/song.md
130
+ - docs/docs/index.md
131
+ - docs/mkdocs.yml
132
+ - docs/serve.sh
133
+ - docs/site/404.html
134
+ - docs/site/assets/fonts/font-awesome.css
135
+ - docs/site/assets/fonts/material-icons.css
136
+ - docs/site/assets/fonts/specimen/FontAwesome.ttf
137
+ - docs/site/assets/fonts/specimen/FontAwesome.woff
138
+ - docs/site/assets/fonts/specimen/FontAwesome.woff2
139
+ - docs/site/assets/fonts/specimen/MaterialIcons-Regular.ttf
140
+ - docs/site/assets/fonts/specimen/MaterialIcons-Regular.woff
141
+ - docs/site/assets/fonts/specimen/MaterialIcons-Regular.woff2
142
+ - docs/site/assets/images/favicon.png
143
+ - docs/site/assets/images/icons/bitbucket.1b09e088.svg
144
+ - docs/site/assets/images/icons/github.f0b8504a.svg
145
+ - docs/site/assets/images/icons/gitlab.6dd19c00.svg
146
+ - docs/site/assets/javascripts/application.c648116f.js
147
+ - docs/site/assets/javascripts/lunr/lunr.da.js
148
+ - docs/site/assets/javascripts/lunr/lunr.de.js
149
+ - docs/site/assets/javascripts/lunr/lunr.du.js
150
+ - docs/site/assets/javascripts/lunr/lunr.es.js
151
+ - docs/site/assets/javascripts/lunr/lunr.fi.js
152
+ - docs/site/assets/javascripts/lunr/lunr.fr.js
153
+ - docs/site/assets/javascripts/lunr/lunr.hu.js
154
+ - docs/site/assets/javascripts/lunr/lunr.it.js
155
+ - docs/site/assets/javascripts/lunr/lunr.ja.js
156
+ - docs/site/assets/javascripts/lunr/lunr.jp.js
157
+ - docs/site/assets/javascripts/lunr/lunr.multi.js
158
+ - docs/site/assets/javascripts/lunr/lunr.nl.js
159
+ - docs/site/assets/javascripts/lunr/lunr.no.js
160
+ - docs/site/assets/javascripts/lunr/lunr.pt.js
161
+ - docs/site/assets/javascripts/lunr/lunr.ro.js
162
+ - docs/site/assets/javascripts/lunr/lunr.ru.js
163
+ - docs/site/assets/javascripts/lunr/lunr.stemmer.support.js
164
+ - docs/site/assets/javascripts/lunr/lunr.sv.js
165
+ - docs/site/assets/javascripts/lunr/lunr.th.js
166
+ - docs/site/assets/javascripts/lunr/lunr.tr.js
167
+ - docs/site/assets/javascripts/lunr/tinyseg.js
168
+ - docs/site/assets/javascripts/lunr/wordcut.js
169
+ - docs/site/assets/javascripts/modernizr.74668098.js
170
+ - docs/site/assets/stylesheets/application-palette.a8b3c06d.css
171
+ - docs/site/assets/stylesheets/application.30686662.css
172
+ - docs/site/commands/crypto/index.html
173
+ - docs/site/commands/song/index.html
174
+ - docs/site/index.html
175
+ - docs/site/search/search_index.json
176
+ - docs/site/sitemap.xml
177
+ - docs/site/sitemap.xml.gz
178
+ - exe/siren
179
+ - lib/siren.rb
180
+ - lib/siren/cli.rb
181
+ - lib/siren/crypto.rb
182
+ - lib/siren/song.rb
183
+ - lib/siren/stack.rb
184
+ - lib/siren/version.rb
185
+ - public.jwk
186
+ homepage: http://docs.altaire.xyz/siren
187
+ licenses:
188
+ - MIT
189
+ metadata:
190
+ homepage_uri: http://docs.altaire.xyz/siren
191
+ post_install_message:
192
+ rdoc_options: []
193
+ require_paths:
194
+ - lib
195
+ required_ruby_version: !ruby/object:Gem::Requirement
196
+ requirements:
197
+ - - ">="
198
+ - !ruby/object:Gem::Version
199
+ version: '0'
200
+ required_rubygems_version: !ruby/object:Gem::Requirement
201
+ requirements:
202
+ - - ">="
203
+ - !ruby/object:Gem::Version
204
+ version: '0'
205
+ requirements: []
206
+ rubygems_version: 3.0.6
207
+ signing_key:
208
+ specification_version: 4
209
+ summary: Kubernetes controller and client utility
210
+ test_files: []