fastlane-plugin-dropbox 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8ea3802e7d6f6303249be04205d0c152474e3bae
4
+ data.tar.gz: bd7e8e8c9c76db3d960dc32c4105019b2a97a434
5
+ SHA512:
6
+ metadata.gz: cb02b5404cbdb428649712c5a1fafc48ddfe79578b9870c1e97e9068d084d389e0e331d095e80cd7caf520c343b0014f8241bee8ab6d815672b9292cbb3b2c04
7
+ data.tar.gz: 3ed6e4330e586e25897d545a7d41ef4f341d8b76b93d23011696f92b6a7453c67025c40d72511e80b7be00c8d3cef8c512dfa818fc5897ca61d6cef8e19f3862
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Dominik Kapusta <dominik@kapusta.cc>
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.
@@ -0,0 +1,63 @@
1
+ # dropbox plugin
2
+
3
+ [![fastlane Plugin Badge](https://rawcdn.githack.com/fastlane/fastlane/master/fastlane/assets/plugin-badge.svg)](https://rubygems.org/gems/fastlane-plugin-dropbox)
4
+
5
+ ## Getting Started
6
+
7
+ This project is a [_fastlane_](https://github.com/fastlane/fastlane) plugin. To get started with `fastlane-plugin-dropbox`, add it to your project by running:
8
+
9
+ ```bash
10
+ fastlane add_plugin dropbox
11
+ ```
12
+
13
+ ## About
14
+
15
+ This plugin allows for uploading files to Dropbox from Fastlane, using provided Dropbox client application.
16
+
17
+ ## Setting up
18
+
19
+ **Note:** Dropbox allows accessing their API only for authorized applications, so in order to use this plugin you must register a Dropbox app.
20
+
21
+ In order to register a Dropbox app you need to go to [Dropbox Developers](https://www.dropbox.com/developers/apps) site and create your own app.
22
+
23
+ 1. For Fastlane you only need the app key and app secret. You'll also have to come up with some name for the app, but this is not used by Fastlane in any way.
24
+ 1. You also don't need to apply for production state of your app, and keep it in development phase unless you make heavy use of it. Even Dropbox themselves encourage staying in development state when the app is used as an internal tool. Read more [here](https://www.dropbox.com/developers/reference/developer-guide#production-approval).
25
+ 1. You start with access for one user only, but in development state you can request access for up to 500 users, which should cover most of the use cases for Fastlane integration.
26
+
27
+ ## Example
28
+
29
+ dropbox(
30
+ file_path: '/some/local-path/to/file.txt',
31
+ dropbox_path: '/path/to/Dropbox/destination/folder',
32
+ app_key: 'your-dropbox-app-key',
33
+ app_secret: 'your-dropbox-app-secret'
34
+ )
35
+
36
+ ## Run tests for this plugin
37
+
38
+ To run both the tests, and code style validation, run
39
+
40
+ ```
41
+ rake
42
+ ```
43
+
44
+ To automatically fix many of the styling issues, use
45
+ ```
46
+ rubocop -a
47
+ ```
48
+
49
+ ## Issues and Feedback
50
+
51
+ For any other issues and feedback about this plugin, please submit it to this repository.
52
+
53
+ ## Troubleshooting
54
+
55
+ If you have trouble using plugins, check out the [Plugins Troubleshooting](https://docs.fastlane.tools/plugins/plugins-troubleshooting/) guide.
56
+
57
+ ## Using _fastlane_ Plugins
58
+
59
+ For more information about how the `fastlane` plugin system works, check out the [Plugins documentation](https://docs.fastlane.tools/plugins/create-plugin/).
60
+
61
+ ## About _fastlane_
62
+
63
+ _fastlane_ is the easiest way to automate beta deployments and releases for your iOS and Android apps. To learn more, check out [fastlane.tools](https://fastlane.tools).
@@ -0,0 +1,16 @@
1
+ require 'fastlane/plugin/dropbox/version'
2
+
3
+ module Fastlane
4
+ module Dropbox
5
+ # Return all .rb files inside the "actions" and "helper" directory
6
+ def self.all_classes
7
+ Dir[File.expand_path('**/{actions,helper}/*.rb', File.dirname(__FILE__))]
8
+ end
9
+ end
10
+ end
11
+
12
+ # By default we want to import all available actions and helpers
13
+ # A plugin can contain any number of actions and plugins
14
+ Fastlane::Dropbox.all_classes.each do |current|
15
+ require current
16
+ end
@@ -0,0 +1,209 @@
1
+ require 'net/http'
2
+ require 'dropbox_api'
3
+
4
+ module Fastlane
5
+ module Actions
6
+ class DropboxAction < Action
7
+ KEYCHAIN_SERVICE_NAME = 'fastlane-plugin-dropbox'.freeze
8
+
9
+ def self.run(params)
10
+ UI.message ''
11
+ UI.message "Starting upload of #{params[:file_path]} to Dropbox"
12
+ UI.message ''
13
+
14
+ params[:keychain] ||= default_keychain
15
+
16
+ access_token = get_token_from_keychain(params[:keychain], params[:keychain_password])
17
+ unless access_token
18
+ access_token = request_token(params[:app_key], params[:app_secret])
19
+ unless save_token_to_keychain(params[:keychain], access_token)
20
+ UI.user_error! 'Failed to store access token in the keychain'
21
+ end
22
+ end
23
+
24
+ client = DropboxApi::Client.new(access_token)
25
+
26
+ output_file_name = nil
27
+
28
+ chunk_size = 157_286_400 # 150 megabytes
29
+
30
+ if File.size(params[:file_path]) < chunk_size
31
+ file = client.upload destination_path(params), File.read(params[:file_path])
32
+ output_file_name = file.name
33
+ else
34
+ parts = chunker params[:file_path], './part', chunk_size
35
+
36
+ UI.message ''
37
+ UI.important "The archive is a big file so we're uploading it in 150MB chunks"
38
+ UI.message ''
39
+
40
+ UI.message "Uploading part #1 (#{File.size(parts[0])} bytes)..."
41
+ cursor = client.upload_session_start File.read(parts[0])
42
+ parts[1..parts.size].each_with_index do |part, index|
43
+ UI.message "Uploading part ##{index + 2} (#{File.size(part)} bytes)..."
44
+ client.upload_session_append_v2 cursor, File.read(part)
45
+ end
46
+ file = client.upload_session_finish cursor, DropboxApi::Metadata::CommitInfo.new('path' => destination_path(params),
47
+ 'mode' => :add)
48
+ output_file_name = file.name
49
+ parts.each { |part| File.delete(part) }
50
+ end
51
+
52
+ if output_file_name != File.basename(params[:file_path])
53
+ UI.user_error! 'Failed to upload archive to Dropbox'
54
+ else
55
+ UI.success "Successfully uploaded archive to Dropbox at '#{destination_path(params)}'"
56
+ end
57
+ end
58
+
59
+ def self.destination_path(params)
60
+ "#{params[:dropbox_path]}/#{File.basename(params[:file_path])}"
61
+ end
62
+
63
+ def self.default_keychain
64
+ `security default-keychain`.chomp.gsub(/.+"(.+)"/, '\\1')
65
+ end
66
+
67
+ def self.get_token_from_keychain(keychain, password)
68
+ other_action.unlock_keychain(
69
+ path: keychain,
70
+ password: password
71
+ )
72
+ token = `security find-generic-password -s #{KEYCHAIN_SERVICE_NAME} -w "#{keychain}" 2>/dev/null`.chomp
73
+ $CHILD_STATUS >> 8 == 0 ? token : nil
74
+ end
75
+
76
+ def self.save_token_to_keychain(keychain, access_token)
77
+ `security add-generic-password -a #{KEYCHAIN_SERVICE_NAME} -s #{KEYCHAIN_SERVICE_NAME} -w "#{access_token}" "#{keychain}"`
78
+ $CHILD_STATUS >> 8 == 0
79
+ end
80
+
81
+ def self.chunker(f_in, out_pref, chunksize)
82
+ parts = []
83
+ File.open(f_in, 'r') do |fh_in|
84
+ until fh_in.eof?
85
+ part = "#{out_pref}_#{format('%05d', (fh_in.pos / chunksize))}"
86
+ File.open(part, 'w') do |fh_out|
87
+ fh_out << fh_in.read(chunksize)
88
+ end
89
+ parts << part
90
+ end
91
+ end
92
+ parts
93
+ end
94
+
95
+ def self.request_token(app_key, app_secret)
96
+ sh("open 'https://www.dropbox.com/oauth2/authorize?response_type=code&require_role=work&client_id=#{app_key}'")
97
+ UI.message 'Please autorize fastlane Dropbox plugin to access your Dropbox account via your Dropbox app'
98
+ authorization_code = UI.input('Once authorized, please paste the authorization code here: ')
99
+
100
+ uri = URI('https://api.dropboxapi.com/oauth2/token')
101
+ req = Net::HTTP::Post.new(uri)
102
+ req.basic_auth app_key, app_secret
103
+ req.set_form_data(
104
+ 'grant_type' => 'authorization_code',
105
+ 'code' => authorization_code
106
+ )
107
+
108
+ res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
109
+ http.request(req)
110
+ end
111
+
112
+ case res
113
+ when Net::HTTPSuccess, Net::HTTPRedirection
114
+ json = JSON.parse(res.body)
115
+ access_token = json['access_token']
116
+ UI.success('Successfully authorized fastlane plugin to access Dropbox')
117
+ access_token
118
+ else
119
+ UI.user_error!("Error during authorization with Dropbox: #{res.code} - #{res.body}")
120
+ end
121
+ end
122
+
123
+ #####################################################
124
+ # @!group Documentation
125
+ #####################################################
126
+
127
+ def self.description
128
+ 'Uploads files to Dropbox'
129
+ end
130
+
131
+ def self.details
132
+ 'You have to authorize the action before using it. The access token is stored in your default keychain'
133
+ end
134
+
135
+ def self.available_options
136
+ [
137
+ FastlaneCore::ConfigItem.new(key: :file_path,
138
+ env_name: 'DROPBOX_FILE_PATH',
139
+ description: 'Path to the uploaded file',
140
+ type: String,
141
+ optional: false,
142
+ verify_block: proc do |value|
143
+ UI.user_error!("No file path specified for upload to Dropbox, pass using `file_path: 'path_to_file'`") unless value && !value.empty?
144
+ UI.user_error!("Couldn't find file at path '#{value}'") unless File.exist?(value)
145
+ end),
146
+ FastlaneCore::ConfigItem.new(key: :dropbox_path,
147
+ env_name: 'DROPBOX_PATH',
148
+ description: 'Path to the destination Dropbox folder',
149
+ type: String,
150
+ optional: true),
151
+ FastlaneCore::ConfigItem.new(key: :app_key,
152
+ env_name: 'DROPBOX_APP_KEY',
153
+ description: 'App Key of your Dropbox app',
154
+ type: String,
155
+ optional: false,
156
+ verify_block: proc do |value|
157
+ UI.user_error!("App Key not specified for Dropbox app. Provide your app's App Key or create a new app at https://www.dropbox.com/developers if you don't have an app yet.") unless value && !value.empty?
158
+ end),
159
+ FastlaneCore::ConfigItem.new(key: :app_secret,
160
+ env_name: 'DROPBOX_APP_SECRET',
161
+ description: 'App Secret of your Dropbox app',
162
+ type: String,
163
+ optional: false,
164
+ verify_block: proc do |value|
165
+ UI.user_error!("App Secret not specified for Dropbox app. Provide your app's App Secret or create a new app at https://www.dropbox.com/developers if you don't have an app yet.") unless value && !value.empty?
166
+ end),
167
+ FastlaneCore::ConfigItem.new(key: :keychain,
168
+ env_name: 'DROPBOX_KEYCHAIN',
169
+ description: 'Path to keychain where the access token would be stored. Will use default keychain if no value is provided',
170
+ type: String,
171
+ optional: true,
172
+ verify_block: proc do |value|
173
+ UI.user_error!("Couldn't find keychain at path '#{value}'") unless File.exist?(value)
174
+ end),
175
+ FastlaneCore::ConfigItem.new(key: :keychain_password,
176
+ env_name: 'DROPBOX_KEYCHAIN_PASSWORD',
177
+ description: 'Password to unlock keychain. If not provided, the plugin would ask for password',
178
+ type: String,
179
+ optional: true)
180
+ ]
181
+ end
182
+
183
+ def self.output; end
184
+
185
+ def self.return_value
186
+ 'nil or error message'
187
+ end
188
+
189
+ def self.authors
190
+ ['Dominik Kapusta']
191
+ end
192
+
193
+ def self.example_code
194
+ [
195
+ 'dropbox(
196
+ file_path: "./path/to/file.txt",
197
+ dropbox_path: "/My Dropbox Folder/Text files",
198
+ app_key: "dropbox-app-key",
199
+ app_secret: "dropbox-app-secret"
200
+ )'
201
+ ]
202
+ end
203
+
204
+ def self.is_supported?(_platform)
205
+ true
206
+ end
207
+ end
208
+ end
209
+ end
@@ -0,0 +1,12 @@
1
+ module Fastlane
2
+ module Helper
3
+ class DropboxHelper
4
+ # class methods that you define here become available in your action
5
+ # as `Helper::DropboxHelper.your_method`
6
+ #
7
+ def self.show_message
8
+ UI.message('Hello from the dropbox plugin helper!')
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ module Fastlane
2
+ module Dropbox
3
+ VERSION = '0.1.0'.freeze
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,175 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fastlane-plugin-dropbox
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Dominik Kapusta
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-12-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: dropbox_api
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: fastlane
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 2.68.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.68.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
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: rspec_junit_formatter
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
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '='
116
+ - !ruby/object:Gem::Version
117
+ version: 0.49.1
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '='
123
+ - !ruby/object:Gem::Version
124
+ version: 0.49.1
125
+ - !ruby/object:Gem::Dependency
126
+ name: simplecov
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description:
140
+ email: dominik@kapusta.cc
141
+ executables: []
142
+ extensions: []
143
+ extra_rdoc_files: []
144
+ files:
145
+ - LICENSE
146
+ - README.md
147
+ - lib/fastlane/plugin/dropbox.rb
148
+ - lib/fastlane/plugin/dropbox/actions/dropbox_action.rb
149
+ - lib/fastlane/plugin/dropbox/helper/dropbox_helper.rb
150
+ - lib/fastlane/plugin/dropbox/version.rb
151
+ homepage: https://github.com/ayoy/fastlane-plugin-dropbox
152
+ licenses:
153
+ - MIT
154
+ metadata: {}
155
+ post_install_message:
156
+ rdoc_options: []
157
+ require_paths:
158
+ - lib
159
+ required_ruby_version: !ruby/object:Gem::Requirement
160
+ requirements:
161
+ - - ">="
162
+ - !ruby/object:Gem::Version
163
+ version: '0'
164
+ required_rubygems_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ requirements: []
170
+ rubyforge_project:
171
+ rubygems_version: 2.5.2
172
+ signing_key:
173
+ specification_version: 4
174
+ summary: Uploads files to Dropbox
175
+ test_files: []