enviroblyd 0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: b81463a8874ddb4e39f2b619dfc2440298410126b73157cc964688a9f95b74dd
4
+ data.tar.gz: ead65dfc10f447f988fed49b538be98e5177bb0d92f0c13b4c84eff83d765e3c
5
+ SHA512:
6
+ metadata.gz: 66feb39057db61044bfe53e025de79d670f5b7522acba5177e3d76f50aa61f540dd55c659bdf6183fa0c5aa460f2da5c1b485c2f8e7c5e3761dd2d3cbafe65e0
7
+ data.tar.gz: bf189c39256092373dfaccb8682dfa93b17b232c0f9acb62e6cd44866503dbf027428e6ed3db578f6021fba1e2750a14689ebbad6166743c25357141ff2f89b5
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Envirobly
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/bin/enviroblyd ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "enviroblyd"
5
+
6
+ Enviroblyd::Cli::Main.start(ARGV)
@@ -0,0 +1,7 @@
1
+ require "thor"
2
+
3
+ class Enviroblyd::Base < Thor
4
+ def self.exit_on_failure?
5
+ true
6
+ end
7
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+ require "net/http"
3
+ require "uri"
4
+
5
+ class Enviroblyd::Cli::Main < Enviroblyd::Base
6
+ desc "version", "Show version"
7
+ def version
8
+ puts Enviroblyd::VERSION
9
+ end
10
+
11
+ TOKEN_TTL_SECONDS = 30
12
+ IMDS_HOST = ENV.fetch("ENVIROBLYD_IMDS_HOST", "[fd00:ec2::254]")
13
+ API_HOST = ENV.fetch("ENVIROBLYD_API_HOST", "envirobly.com")
14
+ desc "boot", "Get IMDSv2 metadata"
15
+ def boot
16
+ token = http("http://#{IMDS_HOST}/latest/api/token").body.chomp("")
17
+ puts "token: #{token} ."
18
+ instance_id = http("http://#{IMDS_HOST}/latest/meta-data/instance-id").body.chomp("")
19
+ puts "instance_id: #{instance_id} ."
20
+
21
+ response = http("https://#{API_HOST}/api/v1/boots/#{instance_id}", retry_interval: 3, retries: 5, backoff: :exponential)
22
+ puts "/api/v1/boots response code: #{response.code}"
23
+ end
24
+
25
+ private
26
+ def http(url, type: Net::HTTP::Get, headers: {}, retry_interval: 1, retries: 30, backoff: false, success_codes: 200..299, tries: 1)
27
+ uri = URI(url)
28
+ http = Net::HTTP.new uri.host, uri.port
29
+ http.use_ssl = true if uri.scheme == "https"
30
+ http.open_timeout = 5
31
+ http.read_timeout = 5
32
+
33
+ request = type.new(uri, headers)
34
+ # request.content_type = CONTENT_TYPE
35
+
36
+ yield request if block_given?
37
+
38
+ response = http.request(request)
39
+ if success_codes.include?(response.code.to_i)
40
+ response
41
+ elsif retries <= tries
42
+ $stderr.puts "Retried #{tries} times. Aborting."
43
+ exit 1
44
+ else
45
+ sleep_time = (backoff == :exponential) ? (retry_interval * tries) : retry_interval
46
+ puts "Try #{uri} in #{sleep_time}s"
47
+ sleep sleep_time
48
+ http(url, type:, retry_interval:, retries:, backoff:, success_codes:, tries: (tries + 1))
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Enviroblyd
4
+ VERSION = "0.1"
5
+ end
data/lib/enviroblyd.rb ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Enviroblyd
4
+ end
5
+
6
+ # require "active_support"
7
+ # require "active_support/core_ext"
8
+ require "zeitwerk"
9
+
10
+ loader = Zeitwerk::Loader.for_gem
11
+ loader.setup
12
+ loader.eager_load
metadata ADDED
@@ -0,0 +1,91 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: enviroblyd
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Robert Starsi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-09-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: thor
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '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.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: zeitwerk
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.6'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: debug
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.8'
55
+ description:
56
+ email: klevo@klevo.sk
57
+ executables:
58
+ - enviroblyd
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - LICENSE
63
+ - bin/enviroblyd
64
+ - lib/enviroblyd.rb
65
+ - lib/enviroblyd/base.rb
66
+ - lib/enviroblyd/cli/main.rb
67
+ - lib/enviroblyd/version.rb
68
+ homepage: https://github.com/envirobly/enviroblyd
69
+ licenses:
70
+ - MIT
71
+ metadata: {}
72
+ post_install_message:
73
+ rdoc_options: []
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ required_rubygems_version: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - ">="
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ requirements: []
87
+ rubygems_version: 3.5.14
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Envirobly instance daemon
91
+ test_files: []