appstage 0.0.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 +7 -0
- data/bin/appstage +4 -0
- data/lib/appstage.rb +77 -0
- data/lib/delete_files.rb +42 -0
- data/lib/list_files.rb +34 -0
- data/lib/upload_file.rb +67 -0
- metadata +77 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 4ab47184a2617b7b858dbd6fe2f63d50d688e0fbde0b5c13dd0b2f8175796737
|
4
|
+
data.tar.gz: 0b9ddc21aa8243c89f27b30ad37d8668a18888d32696dae24f209ad57e28f095
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e0ca6b1a015ce7e7ffa838f997b866a8cf32e05c957f18fe71933d4b5b3da66dc3bf49dab9dc5640e1a1ac1ea544e1fdfb4a382144de97c36b67bd4ec4ddc3a0
|
7
|
+
data.tar.gz: 2c6ead4430ba518b3a9630e2be89a791d13fa3db4a3845c44c5656b801ec5692a178a791fb04ba1bd6e682a047225a25598a121a10f634fddd6e467e30c9f9d5
|
data/bin/appstage
ADDED
data/lib/appstage.rb
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
#Appstage cli for uploading live builds
|
2
|
+
require 'optparse'
|
3
|
+
require 'httparty' #GEM
|
4
|
+
require 'digest'
|
5
|
+
require 'mimemagic'
|
6
|
+
require 'list_files'
|
7
|
+
require 'delete_files'
|
8
|
+
require 'upload_file'
|
9
|
+
|
10
|
+
module AppStage
|
11
|
+
|
12
|
+
def self.execute
|
13
|
+
options = {}
|
14
|
+
|
15
|
+
option_parser = OptionParser.new do |parser|
|
16
|
+
parser.banner = "Appstage CLI V#{Gem::Specification::load("appstage.gemspec").version}\n" <<
|
17
|
+
"Usage: appstage <command> [options]"
|
18
|
+
|
19
|
+
parser.separator " Commands:-"
|
20
|
+
|
21
|
+
parser.on("-u", "--upload [PATTERN]", "Upload a file to the live build release") do |c|
|
22
|
+
options[:upload] = c
|
23
|
+
end
|
24
|
+
|
25
|
+
parser.on("-d", "--delete [PATTERN]", "Delete a file to the live build release") do |c|
|
26
|
+
options[:delete] = c
|
27
|
+
end
|
28
|
+
|
29
|
+
parser.on("-l", "--list [PATTERN]", "Lists files the live build release") do |c|
|
30
|
+
options[:list] = c
|
31
|
+
end
|
32
|
+
|
33
|
+
parser.on("-h", "--help", "Show this help message") do
|
34
|
+
puts parser
|
35
|
+
end
|
36
|
+
|
37
|
+
parser.separator " Options:-"
|
38
|
+
|
39
|
+
parser.on("-j", "--jwttoken JWT", "Your appstage.io account JWT token") do |v|
|
40
|
+
options[:jwt] = v
|
41
|
+
end
|
42
|
+
|
43
|
+
parser.on("-p", "--project_id ID", "Your appstage.io project id") do |v|
|
44
|
+
options[:project_id] = v
|
45
|
+
end
|
46
|
+
|
47
|
+
parser.on("-h", "--host HOSTURL", "The appstage host, optional, leave blank to use live server") do |v|
|
48
|
+
options[:host] = v
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
begin
|
53
|
+
option_parser.parse!
|
54
|
+
rescue Exception => e
|
55
|
+
puts "Invalid invocation - #{e.message}"
|
56
|
+
puts option_parser.help
|
57
|
+
exit 1
|
58
|
+
end
|
59
|
+
|
60
|
+
if !options.key?(:upload) && !options.key?(:delete) && !options.key?(:list)
|
61
|
+
puts option_parser.help
|
62
|
+
exit 1
|
63
|
+
end
|
64
|
+
|
65
|
+
if options.key?(:list)
|
66
|
+
exit ListFiles.new(options).execute
|
67
|
+
end
|
68
|
+
|
69
|
+
if options.key?(:delete)
|
70
|
+
exit DeleteFiles.new(options).execute
|
71
|
+
end
|
72
|
+
|
73
|
+
if options.key?(:upload)
|
74
|
+
exit UploadFile.new(options).execute
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
data/lib/delete_files.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
module AppStage
|
2
|
+
|
3
|
+
class DeleteFiles
|
4
|
+
def initialize(options)
|
5
|
+
@options = options
|
6
|
+
end
|
7
|
+
|
8
|
+
def execute
|
9
|
+
begin
|
10
|
+
files_json = ListFiles.new(@options).getFileList
|
11
|
+
pattern = @options[:delete] || ".*"
|
12
|
+
|
13
|
+
matching_files = files_json.select{|f| f['name'].match(/#{pattern}/)}
|
14
|
+
puts "Deleting #{matching_files.count} files"
|
15
|
+
|
16
|
+
matching_files.each do |rf|
|
17
|
+
puts " deleting #{rf['name']}"
|
18
|
+
delete_file(rf['id'])
|
19
|
+
end
|
20
|
+
|
21
|
+
rescue Exception => e
|
22
|
+
puts "Delete failed - #{e.message}"
|
23
|
+
return 1
|
24
|
+
end
|
25
|
+
0
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def delete_file(file_id)
|
31
|
+
host = @options[:host] or "https://www.appstage.io"
|
32
|
+
token = @options[:jwt]
|
33
|
+
|
34
|
+
response = HTTParty.delete(host+"/api/live_builds/#{file_id}.json",
|
35
|
+
:headers => { 'Content-Type' => 'application/json',
|
36
|
+
'Authorization' => "Bearer #{token}"}
|
37
|
+
)
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
data/lib/list_files.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
module AppStage
|
2
|
+
|
3
|
+
class ListFiles
|
4
|
+
def initialize(options)
|
5
|
+
@options = options
|
6
|
+
end
|
7
|
+
|
8
|
+
def execute
|
9
|
+
begin
|
10
|
+
getFileList.each do |rf|
|
11
|
+
puts "#{rf['name']}"
|
12
|
+
end
|
13
|
+
rescue Exception => e
|
14
|
+
puts "File listing failed - #{e.message}"
|
15
|
+
return 1
|
16
|
+
end
|
17
|
+
0
|
18
|
+
end
|
19
|
+
|
20
|
+
def getFileList
|
21
|
+
host = @options[:host] || "https://www.appstage.io"
|
22
|
+
token = @options[:jwt]
|
23
|
+
pattern = @options[:list].nil? ? ".*" : @options[:list]
|
24
|
+
|
25
|
+
response = HTTParty.get(host+"/api/live_builds.json",
|
26
|
+
:headers => { 'Content-Type' => 'application/json',
|
27
|
+
'Authorization' => "Bearer #{token}"}
|
28
|
+
)
|
29
|
+
raise "Server error #{response.code}" if response.code != 200
|
30
|
+
files = JSON.parse(response.body)['release_files'].select{|f| f['name'].match(/#{pattern}/)}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
data/lib/upload_file.rb
ADDED
@@ -0,0 +1,67 @@
|
|
1
|
+
module AppStage
|
2
|
+
|
3
|
+
class UploadFile
|
4
|
+
def initialize(options)
|
5
|
+
@options = options
|
6
|
+
end
|
7
|
+
|
8
|
+
def execute
|
9
|
+
begin
|
10
|
+
host = @options[:host] || "https://www.appstage.io"
|
11
|
+
file_path = File.expand_path(@options[:upload])
|
12
|
+
content_type = MimeMagic.by_path(file_path) || "application/octet-stream"
|
13
|
+
file_contents = File.open(file_path).read
|
14
|
+
filename = File.basename(@options[:upload])
|
15
|
+
token = @options[:jwt]
|
16
|
+
|
17
|
+
puts "Uploading #{filename} #{File.size(file_path)} bytes..."
|
18
|
+
|
19
|
+
json = {blob: {
|
20
|
+
filename: filename,
|
21
|
+
byte_size: File.size(file_path),
|
22
|
+
content_type: content_type,
|
23
|
+
checksum: Digest::MD5.base64digest(file_contents)
|
24
|
+
}}.to_json
|
25
|
+
|
26
|
+
response = HTTParty.post(host+'/api/direct_uploads',
|
27
|
+
:body => json,
|
28
|
+
:headers => { 'Content-Type' => 'application/json',
|
29
|
+
'Authorization' => "Bearer #{token}"}
|
30
|
+
)
|
31
|
+
|
32
|
+
response_json = JSON.parse(response.body)
|
33
|
+
|
34
|
+
direct_url = response_json['direct_upload']['url']
|
35
|
+
headers = response_json['direct_upload']['headers']
|
36
|
+
headers['Connection'] = 'keep-alive'
|
37
|
+
|
38
|
+
response_json = HTTParty.put(direct_url,
|
39
|
+
multipart: true,
|
40
|
+
headers: headers,
|
41
|
+
body: file_contents
|
42
|
+
)
|
43
|
+
response_json = JSON.parse(response.body)
|
44
|
+
|
45
|
+
cloud_stored_file = response_json['signed_id']
|
46
|
+
|
47
|
+
json = {
|
48
|
+
release_file: {
|
49
|
+
cloud_stored_file: cloud_stored_file
|
50
|
+
}
|
51
|
+
}.to_json
|
52
|
+
|
53
|
+
response = HTTParty.post(host+"/api/live_builds.json",
|
54
|
+
:body => json,
|
55
|
+
:headers => { 'Content-Type' => 'application/json',
|
56
|
+
'Authorization' => "Bearer #{token}"}
|
57
|
+
)
|
58
|
+
|
59
|
+
puts "Upload complete"
|
60
|
+
response.code == 200 ? 0 : response.code
|
61
|
+
rescue Exception => e
|
62
|
+
puts "Upload failed - #{e}"
|
63
|
+
0
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
metadata
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: appstage
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.8
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- P4 Innovation Ltd
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-01-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: httparty
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 0.18.1
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 0.18.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: mimemagic
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.3.5
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.3.5
|
41
|
+
description: List, Upload and Delete live build content on appstage.io
|
42
|
+
email:
|
43
|
+
- hello@appstage.io
|
44
|
+
executables:
|
45
|
+
- appstage
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- bin/appstage
|
50
|
+
- lib/appstage.rb
|
51
|
+
- lib/delete_files.rb
|
52
|
+
- lib/list_files.rb
|
53
|
+
- lib/upload_file.rb
|
54
|
+
homepage: https://www.appstage.io
|
55
|
+
licenses:
|
56
|
+
- MIT
|
57
|
+
metadata: {}
|
58
|
+
post_install_message:
|
59
|
+
rdoc_options: []
|
60
|
+
require_paths:
|
61
|
+
- lib
|
62
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
requirements: []
|
73
|
+
rubygems_version: 3.0.3
|
74
|
+
signing_key:
|
75
|
+
specification_version: 4
|
76
|
+
summary: Appstage.io CLI gem
|
77
|
+
test_files: []
|