brick_ftp 0.8.4 → 1.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (146) hide show
  1. checksums.yaml +4 -4
  2. data/.circleci/config.yml +0 -5
  3. data/.rubocop.yml +2 -1
  4. data/.yardopts +1 -0
  5. data/CHANGELOG.md +16 -12
  6. data/Gemfile +2 -0
  7. data/README.md +24 -43
  8. data/Rakefile +2 -0
  9. data/bin/console +1 -0
  10. data/brick_ftp.gemspec +10 -9
  11. data/exe/brick_ftp +1 -0
  12. data/lib/brick_ftp.rb +5 -78
  13. data/lib/brick_ftp/client.rb +35 -411
  14. data/lib/brick_ftp/core_ext.rb +8 -0
  15. data/lib/brick_ftp/core_ext/hash.rb +13 -0
  16. data/lib/brick_ftp/core_ext/hash/compact.rb +13 -0
  17. data/lib/brick_ftp/core_ext/struct.rb +13 -0
  18. data/lib/brick_ftp/core_ext/struct/new.rb +16 -0
  19. data/lib/brick_ftp/restful_api.rb +82 -0
  20. data/lib/brick_ftp/restful_api/add_group_member.rb +44 -0
  21. data/lib/brick_ftp/restful_api/client.rb +179 -0
  22. data/lib/brick_ftp/restful_api/command.rb +21 -0
  23. data/lib/brick_ftp/restful_api/complete_upload.rb +46 -0
  24. data/lib/brick_ftp/restful_api/continue_upload.rb +50 -0
  25. data/lib/brick_ftp/restful_api/copy_folder.rb +46 -0
  26. data/lib/brick_ftp/restful_api/count_folder_contents.rb +36 -0
  27. data/lib/brick_ftp/restful_api/count_users.rb +22 -0
  28. data/lib/brick_ftp/restful_api/create_api_key.rb +46 -0
  29. data/lib/brick_ftp/restful_api/create_behavior.rb +42 -0
  30. data/lib/brick_ftp/restful_api/create_bundle.rb +40 -0
  31. data/lib/brick_ftp/restful_api/create_folder.rb +25 -0
  32. data/lib/brick_ftp/restful_api/create_group.rb +42 -0
  33. data/lib/brick_ftp/restful_api/create_notification.rb +44 -0
  34. data/lib/brick_ftp/restful_api/create_permission.rb +48 -0
  35. data/lib/brick_ftp/restful_api/create_public_key.rb +42 -0
  36. data/lib/brick_ftp/restful_api/create_user.rb +90 -0
  37. data/lib/brick_ftp/restful_api/create_user_in_group.rb +60 -0
  38. data/lib/brick_ftp/restful_api/delete_api_key.rb +23 -0
  39. data/lib/brick_ftp/restful_api/delete_behavior.rb +22 -0
  40. data/lib/brick_ftp/restful_api/delete_bundle.rb +22 -0
  41. data/lib/brick_ftp/restful_api/delete_folder.rb +32 -0
  42. data/lib/brick_ftp/restful_api/delete_group.rb +23 -0
  43. data/lib/brick_ftp/restful_api/delete_notification.rb +23 -0
  44. data/lib/brick_ftp/restful_api/delete_permission.rb +23 -0
  45. data/lib/brick_ftp/restful_api/delete_public_key.rb +23 -0
  46. data/lib/brick_ftp/restful_api/delete_user.rb +25 -0
  47. data/lib/brick_ftp/restful_api/download_file.rb +44 -0
  48. data/lib/brick_ftp/restful_api/get_api_key.rb +25 -0
  49. data/lib/brick_ftp/restful_api/get_behavior.rb +25 -0
  50. data/lib/brick_ftp/restful_api/get_bundle.rb +25 -0
  51. data/lib/brick_ftp/restful_api/get_bundle_zip.rb +48 -0
  52. data/lib/brick_ftp/restful_api/get_file_in_bundle.rb +49 -0
  53. data/lib/brick_ftp/restful_api/get_folder_size.rb +25 -0
  54. data/lib/brick_ftp/restful_api/get_group.rb +26 -0
  55. data/lib/brick_ftp/restful_api/get_public_key.rb +25 -0
  56. data/lib/brick_ftp/restful_api/get_site_usage.rb +19 -0
  57. data/lib/brick_ftp/restful_api/get_user.rb +26 -0
  58. data/lib/brick_ftp/restful_api/list_api_keys.rb +25 -0
  59. data/lib/brick_ftp/restful_api/list_behaviors.rb +23 -0
  60. data/lib/brick_ftp/restful_api/list_bundle_contents.rb +58 -0
  61. data/lib/brick_ftp/restful_api/list_bundles.rb +23 -0
  62. data/lib/brick_ftp/restful_api/list_folder_behaviors.rb +39 -0
  63. data/lib/brick_ftp/restful_api/list_folders.rb +108 -0
  64. data/lib/brick_ftp/restful_api/list_groups.rb +23 -0
  65. data/lib/brick_ftp/restful_api/list_notifications.rb +23 -0
  66. data/lib/brick_ftp/restful_api/list_permissions.rb +41 -0
  67. data/lib/brick_ftp/restful_api/list_public_keys.rb +25 -0
  68. data/lib/brick_ftp/restful_api/list_users.rb +60 -0
  69. data/lib/brick_ftp/restful_api/move_folder.rb +41 -0
  70. data/lib/brick_ftp/restful_api/remove_group_member.rb +23 -0
  71. data/lib/brick_ftp/restful_api/retrieve_file_history.rb +41 -0
  72. data/lib/brick_ftp/restful_api/retrieve_folder_history.rb +41 -0
  73. data/lib/brick_ftp/restful_api/retrieve_history.rb +54 -0
  74. data/lib/brick_ftp/restful_api/retrieve_login_history.rb +38 -0
  75. data/lib/brick_ftp/restful_api/retrieve_site_history.rb +38 -0
  76. data/lib/brick_ftp/restful_api/retrieve_user_history.rb +40 -0
  77. data/lib/brick_ftp/restful_api/search_user.rb +28 -0
  78. data/lib/brick_ftp/restful_api/start_upload.rb +27 -0
  79. data/lib/brick_ftp/restful_api/unlock_user.rb +25 -0
  80. data/lib/brick_ftp/restful_api/update_behavior.rb +39 -0
  81. data/lib/brick_ftp/restful_api/update_group.rb +44 -0
  82. data/lib/brick_ftp/restful_api/update_group_member.rb +40 -0
  83. data/lib/brick_ftp/restful_api/update_user.rb +101 -0
  84. data/lib/brick_ftp/restful_api/upload_file.rb +65 -0
  85. data/lib/brick_ftp/types.rb +23 -0
  86. data/lib/brick_ftp/types/behavior.rb +27 -0
  87. data/lib/brick_ftp/types/bundle.rb +34 -0
  88. data/lib/brick_ftp/types/bundle_content.rb +25 -0
  89. data/lib/brick_ftp/types/bundle_zip.rb +19 -0
  90. data/lib/brick_ftp/types/file.rb +45 -0
  91. data/lib/brick_ftp/types/file_in_bundle.rb +25 -0
  92. data/lib/brick_ftp/types/folder_contents_count.rb +24 -0
  93. data/lib/brick_ftp/types/group.rb +31 -0
  94. data/lib/brick_ftp/types/group_membership.rb +27 -0
  95. data/lib/brick_ftp/types/history.rb +43 -0
  96. data/lib/brick_ftp/types/notification.rb +31 -0
  97. data/lib/brick_ftp/types/permission.rb +35 -0
  98. data/lib/brick_ftp/types/site_usage.rb +23 -0
  99. data/lib/brick_ftp/types/upload.rb +45 -0
  100. data/lib/brick_ftp/types/user.rb +79 -0
  101. data/lib/brick_ftp/types/user_api_key.rb +33 -0
  102. data/lib/brick_ftp/types/user_public_key.rb +28 -0
  103. data/lib/brick_ftp/utils.rb +2 -0
  104. data/lib/brick_ftp/utils/chunk_io.rb +5 -4
  105. data/lib/brick_ftp/version.rb +3 -1
  106. metadata +123 -86
  107. data/lib/brick_ftp/api.rb +0 -9
  108. data/lib/brick_ftp/api/authentication.rb +0 -28
  109. data/lib/brick_ftp/api/authentication/session.rb +0 -25
  110. data/lib/brick_ftp/api/base.rb +0 -119
  111. data/lib/brick_ftp/api/behavior.rb +0 -19
  112. data/lib/brick_ftp/api/bundle.rb +0 -17
  113. data/lib/brick_ftp/api/bundle_content.rb +0 -18
  114. data/lib/brick_ftp/api/bundle_download.rb +0 -18
  115. data/lib/brick_ftp/api/file.rb +0 -20
  116. data/lib/brick_ftp/api/file_operation.rb +0 -6
  117. data/lib/brick_ftp/api/file_operation/copy.rb +0 -10
  118. data/lib/brick_ftp/api/file_operation/move.rb +0 -10
  119. data/lib/brick_ftp/api/file_operation/upload.rb +0 -66
  120. data/lib/brick_ftp/api/file_operation/uploading_result.rb +0 -22
  121. data/lib/brick_ftp/api/file_operation/uploading_session.rb +0 -95
  122. data/lib/brick_ftp/api/folder.rb +0 -22
  123. data/lib/brick_ftp/api/folder_behavior.rb +0 -12
  124. data/lib/brick_ftp/api/group.rb +0 -16
  125. data/lib/brick_ftp/api/history.rb +0 -6
  126. data/lib/brick_ftp/api/history/file.rb +0 -23
  127. data/lib/brick_ftp/api/history/folder.rb +0 -23
  128. data/lib/brick_ftp/api/history/login.rb +0 -23
  129. data/lib/brick_ftp/api/history/site.rb +0 -23
  130. data/lib/brick_ftp/api/history/user.rb +0 -23
  131. data/lib/brick_ftp/api/notification.rb +0 -14
  132. data/lib/brick_ftp/api/permission.rb +0 -17
  133. data/lib/brick_ftp/api/public_key.rb +0 -15
  134. data/lib/brick_ftp/api/site_usage.rb +0 -21
  135. data/lib/brick_ftp/api/user.rb +0 -36
  136. data/lib/brick_ftp/api_component.rb +0 -81
  137. data/lib/brick_ftp/api_definition.rb +0 -65
  138. data/lib/brick_ftp/cli.rb +0 -7
  139. data/lib/brick_ftp/cli/config.rb +0 -20
  140. data/lib/brick_ftp/cli/main.rb +0 -26
  141. data/lib/brick_ftp/cli/site.rb +0 -10
  142. data/lib/brick_ftp/configuration.rb +0 -121
  143. data/lib/brick_ftp/http_client.rb +0 -130
  144. data/lib/brick_ftp/log_formatter.rb +0 -15
  145. data/lib/brick_ftp/webhook.rb +0 -4
  146. data/lib/brick_ftp/webhook/request.rb +0 -28
@@ -1,22 +0,0 @@
1
- module BrickFTP
2
- module API
3
- class Folder < Base
4
- # rubocop:disable Metrics/LineLength
5
- endpoint :get, :index, '/api/rest/v1/folders/%{path}', :page, :per_page, :search, :'sort_by[path]', :'sort_by[size]', :'sort_by[modified_at_datetime]'
6
- # rubocop:enable Metrics/LineLength
7
- endpoint :post, :create, '/api/rest/v1/folders/%{path}'
8
-
9
- attribute :id
10
- attribute :path
11
- attribute :display_name
12
- attribute :type
13
- attribute :size
14
- attribute :mtime
15
- attribute :crc32
16
- attribute :md5
17
- attribute :provided_mtime
18
- attribute :permissions
19
- attribute :subfolders_locked?
20
- end
21
- end
22
- end
@@ -1,12 +0,0 @@
1
- module BrickFTP
2
- module API
3
- class FolderBehavior < Base
4
- endpoint :get, :index, '/api/rest/v1/behaviors/folders/%{path}', :recursive
5
-
6
- attribute :id
7
- attribute :path
8
- attribute :behavior
9
- attribute :value
10
- end
11
- end
12
- end
@@ -1,16 +0,0 @@
1
- module BrickFTP
2
- module API
3
- class Group < Base
4
- endpoint :get, :index, '/api/rest/v1/groups.json'
5
- endpoint :get, :show, '/api/rest/v1/groups/%{id}.json'
6
- endpoint :post, :create, '/api/rest/v1/groups.json'
7
- endpoint :put, :update, '/api/rest/v1/groups/%{id}.json'
8
- endpoint :delete, :delete, '/api/rest/v1/groups/%{id}.json'
9
-
10
- attribute :id
11
- attribute :name, writable: true
12
- attribute :notes, writable: true
13
- attribute :user_ids, writable: true
14
- end
15
- end
16
- end
@@ -1,6 +0,0 @@
1
- module BrickFTP
2
- module API
3
- module History
4
- end
5
- end
6
- end
@@ -1,23 +0,0 @@
1
- module BrickFTP
2
- module API
3
- module History
4
- class File < BrickFTP::API::Base
5
- endpoint :get, :index, '/api/rest/v1/history/files/%{path}', :page, :per_page, :start_at
6
-
7
- attribute :id
8
- attribute :when
9
- attribute :user_id
10
- attribute :username
11
- attribute :action
12
- attribute :failure_type
13
- attribute :path
14
- attribute :source
15
- attribute :destination
16
- attribute :targets
17
- attribute :ip
18
- attribute :interface
19
- attribute :display
20
- end
21
- end
22
- end
23
- end
@@ -1,23 +0,0 @@
1
- module BrickFTP
2
- module API
3
- module History
4
- class Folder < BrickFTP::API::Base
5
- endpoint :get, :index, '/api/rest/v1/history/folders/%{path}', :page, :per_page, :start_at
6
-
7
- attribute :id
8
- attribute :when
9
- attribute :user_id
10
- attribute :username
11
- attribute :action
12
- attribute :failure_type
13
- attribute :path
14
- attribute :source
15
- attribute :destination
16
- attribute :targets
17
- attribute :ip
18
- attribute :interface
19
- attribute :display
20
- end
21
- end
22
- end
23
- end
@@ -1,23 +0,0 @@
1
- module BrickFTP
2
- module API
3
- module History
4
- class Login < BrickFTP::API::Base
5
- endpoint :get, :index, '/api/rest/v1/history/login.json', :page, :per_page, :start_at
6
-
7
- attribute :id
8
- attribute :when
9
- attribute :user_id
10
- attribute :username
11
- attribute :action
12
- attribute :failure_type
13
- attribute :path
14
- attribute :source
15
- attribute :destination
16
- attribute :targets
17
- attribute :ip
18
- attribute :interface
19
- attribute :display
20
- end
21
- end
22
- end
23
- end
@@ -1,23 +0,0 @@
1
- module BrickFTP
2
- module API
3
- module History
4
- class Site < BrickFTP::API::Base
5
- endpoint :get, :index, '/api/rest/v1/history.json', :page, :per_page, :start_at
6
-
7
- attribute :id
8
- attribute :when
9
- attribute :user_id
10
- attribute :username
11
- attribute :action
12
- attribute :failure_type
13
- attribute :path
14
- attribute :source
15
- attribute :destination
16
- attribute :targets
17
- attribute :ip
18
- attribute :interface
19
- attribute :display
20
- end
21
- end
22
- end
23
- end
@@ -1,23 +0,0 @@
1
- module BrickFTP
2
- module API
3
- module History
4
- class User < BrickFTP::API::Base
5
- endpoint :get, :index, '/api/rest/v1/history/users/%{user_id}.json', :page, :per_page, :start_at
6
-
7
- attribute :id
8
- attribute :when
9
- attribute :user_id
10
- attribute :username
11
- attribute :action
12
- attribute :failure_type
13
- attribute :path
14
- attribute :source
15
- attribute :destination
16
- attribute :targets
17
- attribute :ip
18
- attribute :interface
19
- attribute :display
20
- end
21
- end
22
- end
23
- end
@@ -1,14 +0,0 @@
1
- module BrickFTP
2
- module API
3
- class Notification < Base
4
- endpoint :get, :index, '/api/rest/v1/notifications.json'
5
- endpoint :post, :create, '/api/rest/v1/notifications.json'
6
- endpoint :delete, :delete, '/api/rest/v1/notifications/%{id}.json'
7
-
8
- attribute :id
9
- attribute :path, writable: true
10
- attribute :user_id, writable: true
11
- attribute :username, writable: true
12
- end
13
- end
14
- end
@@ -1,17 +0,0 @@
1
- module BrickFTP
2
- module API
3
- class Permission < Base
4
- endpoint :get, :index, '/api/rest/v1/permissions.json'
5
- endpoint :post, :create, '/api/rest/v1/permissions.json'
6
- endpoint :delete, :delete, '/api/rest/v1/permissions/%{id}.json'
7
-
8
- attribute :id
9
- attribute :recursive
10
- attribute :path, writable: true
11
- attribute :permission, writable: true
12
- attribute :user_id, writable: true
13
- attribute :username, writable: true
14
- attribute :group_id, writable: true
15
- end
16
- end
17
- end
@@ -1,15 +0,0 @@
1
- module BrickFTP
2
- module API
3
- class PublicKey < Base
4
- endpoint :get, :index, '/api/rest/v1/users/%{user_id}/public_keys.json'
5
- endpoint :post, :create, '/api/rest/v1/users/%{user_id}/public_keys.json'
6
- endpoint :delete, :delete, '/api/rest/v1/public_keys/%{id}.json'
7
-
8
- attribute :id
9
- attribute :fingerprint
10
- attribute :created_at
11
- attribute :title, writable: true
12
- attribute :public_key, writable: true
13
- end
14
- end
15
- end
@@ -1,21 +0,0 @@
1
- module BrickFTP
2
- module API
3
- class SiteUsage < Base
4
- endpoint :get, :show, '/api/rest/v1/site/usage'
5
-
6
- attribute :id
7
- attribute :live_current_storage
8
- attribute :current_storage
9
- attribute :usage_by_top_level_dir
10
- attribute :high_water_storage
11
- attribute :start_at
12
- attribute :end_at
13
- attribute :created_at
14
- attribute :updated_at
15
-
16
- def self.find
17
- super('')
18
- end
19
- end
20
- end
21
- end
@@ -1,36 +0,0 @@
1
- module BrickFTP
2
- module API
3
- class User < Base
4
- endpoint :get, :index, '/api/rest/v1/users.json'
5
- endpoint :get, :show, '/api/rest/v1/users/%{id}.json'
6
- endpoint :post, :create, '/api/rest/v1/users.json'
7
- endpoint :put, :update, '/api/rest/v1/users/%{id}.json'
8
- endpoint :delete, :delete, '/api/rest/v1/users/%{id}.json'
9
-
10
- attribute :id
11
- attribute :last_login_at
12
- attribute :time_zone
13
- attribute :language
14
- attribute :site_admin
15
- attribute :username, writable: true
16
- attribute :password, writable: true
17
- attribute :name, writable: true
18
- attribute :email, writable: true
19
- attribute :notes, writable: true
20
- attribute :group_ids, writable: true
21
- attribute :ftp_permission, writable: true
22
- attribute :web_permission, writable: true
23
- attribute :sftp_permission, writable: true
24
- attribute :dav_permission, writable: true
25
- attribute :restapi_permission, writable: true
26
- attribute :attachments_permission, writable: true
27
- attribute :self_managed, writable: true
28
- attribute :require_password_change, writable: true
29
- attribute :allowed_ips, writable: true
30
- attribute :user_root, writable: true
31
- attribute :grant_permission, writable: true
32
- attribute :ssl_required, writable: true
33
- attribute :authentication_method, writable: true
34
- end
35
- end
36
- end
@@ -1,81 +0,0 @@
1
- require 'erb'
2
-
3
- module BrickFTP
4
- class APIComponent
5
- attr_reader :path_template, :query_keys
6
-
7
- def initialize(path_template, query_keys = [])
8
- @path_template = path_template.respond_to?(:call) ? path_template : ->(_) { path_template }
9
- @query_keys = query_keys.map(&:to_sym)
10
- end
11
-
12
- def path(params)
13
- params = normalize_params(params)
14
-
15
- path_params = build_path_params_from(params)
16
- escaped_path_params = path_params.each_with_object({}) do |(k, v), res|
17
- res[k] = ERB::Util.url_encode(v.to_s)
18
- end
19
-
20
- path = path_template.call(params) % escaped_path_params
21
- query = build_query_string_from(params)
22
- query.empty? ? path : "#{path}?#{query}"
23
- end
24
-
25
- def build_path_params_from(params = {})
26
- params = normalize_params(params)
27
-
28
- path_variables(params).each_with_object({}) do |key, res|
29
- res[key] = params[key]
30
- end
31
- end
32
-
33
- def build_query_params_from(params = {})
34
- params = normalize_params(params)
35
-
36
- query_keys.each_with_object({}) do |name, res|
37
- next unless params.key?(name)
38
- res[name] = params[name]
39
- end
40
- end
41
-
42
- def build_query_string_from(params = {})
43
- params = normalize_params(params)
44
-
45
- pairs = build_query_params_from(params).each_with_object([]) do |(k, v), res|
46
- res << "#{CGI.escape(k.to_s)}=#{CGI.escape(v.to_s)}"
47
- end
48
- pairs.join('&')
49
- end
50
-
51
- def except_path_and_query(params = {})
52
- params = normalize_params(params)
53
-
54
- exceptions = path_variables(params) + query_keys
55
- params.reject { |k, _| exceptions.include?(k) }
56
- end
57
-
58
- private
59
-
60
- def path_variables(params = {})
61
- @path_variables ||= path_template.call(params).scan(/%\{([^}]+)\}/).map { |m| m.first.to_sym }
62
- end
63
-
64
- def normalize_params(params = {})
65
- case params
66
- when Hash
67
- params.symbolize_keys
68
- when BrickFTP::API::Base
69
- keys = path_variables(params) + query_keys
70
- keys.each_with_object({}) do |key, res|
71
- res[key] = params.read_property(key)
72
- end
73
- else
74
- keys = path_variables(params) + query_keys
75
- keys.each_with_object({}) do |key, res|
76
- res[key] = params
77
- end
78
- end
79
- end
80
- end
81
- end
@@ -1,65 +0,0 @@
1
- module BrickFTP
2
- module APIDefinition
3
- def self.included(klass)
4
- klass.class_eval do
5
- @endpoints = {}
6
- @writable_attributes = []
7
- @readonly_attributes = []
8
-
9
- class << self
10
- attr_reader :endpoints, :writable_attributes, :readonly_attributes
11
- end
12
- end
13
-
14
- klass.extend ClassMethods
15
- end
16
-
17
- module ClassMethods
18
- # Define API endpoint.
19
- # @param http_method [:Symbol] any one of :get, :post, :put, :delete
20
- # @param name [Symbol] any one of :index, :show, :create, :update, :destroy
21
- # @param path_template [Stryng] template of endpoint path.
22
- # @param query_keys [Array] array of query_string's parameter name.
23
- def endpoint(http_method, name, path_template, *query_keys)
24
- endpoints[name] = {
25
- http_method: http_method,
26
- path_template: path_template,
27
- query_keys: query_keys,
28
- }
29
- end
30
-
31
- # Define attribute.
32
- # @param name [Symbol] name of attribute.
33
- # @param writable [Boolean]
34
- def attribute(name, writable: false)
35
- if writable
36
- writable_attributes << name.to_sym
37
- else
38
- readonly_attributes << name.to_sym
39
- end
40
- end
41
-
42
- # Return all attributes.
43
- # @return [Array]
44
- def attributes
45
- writable_attributes + readonly_attributes
46
- end
47
-
48
- # Build path for API endpoint.
49
- # @param name [Symbol]
50
- # @param params [Hash] mixed path parameters and query parameters.
51
- # @return [String]
52
- def api_path_for(name, params = {})
53
- api_component_for(name).path(params)
54
- end
55
-
56
- # Build BrickFTP::APIComponent.
57
- # @param name [Symbol]
58
- # @return [BrickFTP::APIComponent]
59
- def api_component_for(name)
60
- raise BrickFTP::API::NoSuchAPI, "#{name} #{self.name}" unless endpoints.key?(name)
61
- BrickFTP::APIComponent.new(endpoints[name][:path_template], endpoints[name][:query_keys])
62
- end
63
- end
64
- end
65
- end