azure_file_shares 0.1.5

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.
@@ -0,0 +1,78 @@
1
+ module AzureFileShares
2
+ module Operations
3
+ # Operations for Azure File Shares
4
+ class FileSharesOperations < BaseOperation
5
+ # List all file shares in the storage account
6
+ # @param [Hash] options Query parameters
7
+ # @option options [Integer] :maxpagesize The maximum items per page
8
+ # @option options [String] :filter Filter string
9
+ # @return [Array<AzureFileShares::Resources::FileShare>] Collection of file shares
10
+ def list(options = {})
11
+ path = "#{base_path}/fileServices/default/shares"
12
+ response = request(:get, path, options)
13
+
14
+ shares = response["value"] || []
15
+ shares.map { |share_data| AzureFileShares::Resources::FileShare.new(share_data) }
16
+ end
17
+
18
+ # Get a specific file share by name
19
+ # @param [String] share_name Name of the file share
20
+ # @param [Hash] options Query parameters
21
+ # @return [AzureFileShares::Resources::FileShare] File share details
22
+ def get(share_name, options = {})
23
+ path = "#{base_path}/fileServices/default/shares/#{share_name}"
24
+ response = request(:get, path, options)
25
+
26
+ AzureFileShares::Resources::FileShare.new(response)
27
+ end
28
+
29
+ # Create a new file share
30
+ # @param [String] share_name Name of the file share
31
+ # @param [Hash] properties Share properties
32
+ # @option properties [Integer] :shareQuota The maximum size of the share in GiB
33
+ # @option properties [String] :accessTier Access tier (Hot, Cool, Premium)
34
+ # @option properties [Boolean] :enabledProtocols Enabled protocols (SMB, NFS)
35
+ # @return [AzureFileShares::Resources::FileShare] Created file share
36
+ def create(share_name, properties = {})
37
+ path = "#{base_path}/fileServices/default/shares/#{share_name}"
38
+
39
+ body = {
40
+ properties: properties,
41
+ }
42
+
43
+ response = request(:put, path, {}, body)
44
+ AzureFileShares::Resources::FileShare.new(response)
45
+ end
46
+
47
+ # Update an existing file share
48
+ # @param [String] share_name Name of the file share
49
+ # @param [Hash] properties Share properties to update
50
+ # @return [AzureFileShares::Resources::FileShare] Updated file share
51
+ def update(share_name, properties = {})
52
+ path = "#{base_path}/fileServices/default/shares/#{share_name}"
53
+
54
+ body = {
55
+ properties: properties,
56
+ }
57
+
58
+ response = request(:patch, path, {}, body)
59
+ AzureFileShares::Resources::FileShare.new(response)
60
+ end
61
+
62
+ # Delete a file share
63
+ # @param [String] share_name Name of the file share
64
+ # @param [Hash] options Query parameters
65
+ # @option options [Boolean] :delete_snapshots Whether to delete snapshots
66
+ # @return [Boolean] true if successful
67
+ def delete(share_name, options = {})
68
+ path = "#{base_path}/fileServices/default/shares/#{share_name}"
69
+
70
+ delete_options = {}
71
+ delete_options[:deleteSnapshots] = options[:delete_snapshots] if options[:delete_snapshots]
72
+
73
+ request(:delete, path, delete_options)
74
+ true
75
+ end
76
+ end
77
+ end
78
+ end
@@ -0,0 +1,62 @@
1
+ module AzureFileShares
2
+ module Operations
3
+ # Operations for Azure File Share Snapshots
4
+ class SnapshotsOperations < BaseOperation
5
+ # Create a snapshot of a file share
6
+ # @param [String] share_name Name of the file share
7
+ # @param [Hash] metadata Optional metadata for the snapshot
8
+ # @return [AzureFileShares::Resources::FileShareSnapshot] Created snapshot
9
+ def create(share_name, metadata = {})
10
+ path = "#{base_path}/fileServices/default/shares/#{share_name}/snapshots"
11
+
12
+ body = {}
13
+ body[:metadata] = metadata unless metadata.empty?
14
+
15
+ response = request(:post, path, {}, body)
16
+ AzureFileShares::Resources::FileShareSnapshot.new(response)
17
+ end
18
+
19
+ # List snapshots of a file share
20
+ # @param [String] share_name Name of the file share
21
+ # @param [Hash] options Query parameters
22
+ # @return [Array<AzureFileShares::Resources::FileShareSnapshot>] Collection of snapshots
23
+ def list(share_name, options = {})
24
+ path = "#{base_path}/fileServices/default/shares/#{share_name}/snapshots"
25
+ response = request(:get, path, options)
26
+
27
+ snapshots = response["value"] || []
28
+ snapshots.map { |snapshot_data| AzureFileShares::Resources::FileShareSnapshot.new(snapshot_data) }
29
+ end
30
+
31
+ # Get a specific snapshot by share name and snapshot timestamp
32
+ # @param [String] share_name Name of the file share
33
+ # @param [String] snapshot_timestamp Timestamp of the snapshot
34
+ # @return [AzureFileShares::Resources::FileShareSnapshot] Snapshot details
35
+ def get(share_name, snapshot_timestamp)
36
+ path = "#{base_path}/fileServices/default/shares/#{share_name}"
37
+
38
+ options = {
39
+ sharesnapshot: snapshot_timestamp,
40
+ }
41
+
42
+ response = request(:get, path, options)
43
+ AzureFileShares::Resources::FileShareSnapshot.new(response)
44
+ end
45
+
46
+ # Delete a specific snapshot
47
+ # @param [String] share_name Name of the file share
48
+ # @param [String] snapshot_timestamp Timestamp of the snapshot
49
+ # @return [Boolean] true if successful
50
+ def delete(share_name, snapshot_timestamp)
51
+ path = "#{base_path}/fileServices/default/shares/#{share_name}"
52
+
53
+ options = {
54
+ sharesnapshot: snapshot_timestamp,
55
+ }
56
+
57
+ request(:delete, path, options)
58
+ true
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,80 @@
1
+ module AzureFileShares
2
+ module Resources
3
+ # Represents an Azure File Share resource
4
+ class FileShare
5
+ attr_reader :id, :name, :type, :etag, :properties, :metadata
6
+
7
+ # Initialize a new FileShare object from API response
8
+ # @param [Hash] data API response data
9
+ def initialize(data)
10
+ @id = data["id"]
11
+ @name = data["name"]
12
+ @type = data["type"]
13
+ @etag = data["etag"]
14
+ @properties = data["properties"] || {}
15
+ @metadata = data["metadata"] || {}
16
+ end
17
+
18
+ # Get the provisioned capacity in GiB
19
+ # @return [Integer] Quota in GiB
20
+ def quota
21
+ properties["shareQuota"]
22
+ end
23
+
24
+ # Get the access tier (Hot, Cool, Premium)
25
+ # @return [String] Access tier
26
+ def access_tier
27
+ properties["accessTier"]
28
+ end
29
+
30
+ # Get the last modified time
31
+ # @return [Time, nil] Last modified time or nil if not available
32
+ def last_modified_time
33
+ time_str = properties["lastModifiedTime"]
34
+ Time.parse(time_str) if time_str
35
+ rescue ArgumentError, TypeError
36
+ nil
37
+ end
38
+
39
+ # Get the creation time
40
+ # @return [Time, nil] Creation time or nil if not available
41
+ def creation_time
42
+ time_str = properties["creationTime"]
43
+ Time.parse(time_str) if time_str
44
+ rescue ArgumentError, TypeError
45
+ nil
46
+ end
47
+
48
+ # Get the enabled protocols
49
+ # @return [String] Enabled protocols (SMB, NFS)
50
+ def enabled_protocols
51
+ properties["enabledProtocols"]
52
+ end
53
+
54
+ # Get the lease state
55
+ # @return [String] Lease state
56
+ def lease_state
57
+ properties["leaseState"]
58
+ end
59
+
60
+ # Get the lease status
61
+ # @return [String] Lease status
62
+ def lease_status
63
+ properties["leaseStatus"]
64
+ end
65
+
66
+ # Convert object to a hash
67
+ # @return [Hash] The file share as a hash
68
+ def to_h
69
+ {
70
+ id: id,
71
+ name: name,
72
+ type: type,
73
+ etag: etag,
74
+ properties: properties,
75
+ metadata: metadata,
76
+ }
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,75 @@
1
+ module AzureFileShares
2
+ module Resources
3
+ # Represents an Azure File Share Snapshot resource
4
+ class FileShareSnapshot
5
+ attr_reader :id, :name, :type, :etag, :properties, :metadata, :share_name, :snapshot_time
6
+
7
+ # Initialize a new FileShareSnapshot object from API response
8
+ # @param [Hash] data API response data
9
+ def initialize(data)
10
+ @id = data["id"]
11
+ @name = data["name"]
12
+ @type = data["type"]
13
+ @etag = data["etag"]
14
+ @properties = data["properties"] || {}
15
+ @metadata = data["metadata"] || {}
16
+
17
+ # Extract snapshot time from properties directly
18
+ @snapshot_time = properties["snapshot"] if properties && properties["snapshot"]
19
+
20
+ # Extract share name and snapshot time from the ID
21
+ parse_id if @id
22
+ end
23
+
24
+ # Get the provisioned capacity in GiB
25
+ # @return [Integer] Quota in GiB
26
+ def quota
27
+ properties["shareQuota"]
28
+ end
29
+
30
+ # Get the snapshot timestamp
31
+ # @return [String] Snapshot timestamp
32
+ def timestamp
33
+ properties["snapshot"]
34
+ end
35
+
36
+ # Get the creation time
37
+ # @return [Time, nil] Creation time or nil if not available
38
+ def creation_time
39
+ time_str = properties["creationTime"]
40
+ Time.parse(time_str) if time_str
41
+ rescue ArgumentError, TypeError
42
+ nil
43
+ end
44
+
45
+ # Convert object to a hash
46
+ # @return [Hash] The snapshot as a hash
47
+ def to_h
48
+ {
49
+ id: id,
50
+ name: name,
51
+ type: type,
52
+ etag: etag,
53
+ properties: properties,
54
+ metadata: metadata,
55
+ share_name: share_name,
56
+ snapshot_time: snapshot_time,
57
+ }
58
+ end
59
+
60
+ private
61
+
62
+ # Parse the resource ID to extract share name
63
+ def parse_id
64
+ return unless id
65
+
66
+ parts = id.split("/")
67
+ # Find the index of 'shares' and get the next part as the share name
68
+ shares_index = parts.index("shares")
69
+ if shares_index && shares_index < parts.length - 1
70
+ @share_name = parts[shares_index + 1]
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -0,0 +1,3 @@
1
+ module AzureFileShares
2
+ VERSION = "0.1.5"
3
+ end
@@ -0,0 +1,54 @@
1
+ require "faraday"
2
+ require "faraday/retry"
3
+ require "json"
4
+ require "uri"
5
+ require "nokogiri"
6
+
7
+ require_relative "azure_file_shares/version"
8
+ require_relative "azure_file_shares/configuration"
9
+ require_relative "azure_file_shares/client"
10
+
11
+ # Auth
12
+ require_relative "azure_file_shares/auth/token_provider"
13
+
14
+ # Resources
15
+ require_relative "azure_file_shares/resources/file_share"
16
+ require_relative "azure_file_shares/resources/file_share_snapshot"
17
+
18
+ # Operations
19
+ require_relative "azure_file_shares/operations/base_operation"
20
+ require_relative "azure_file_shares/operations/file_shares_operations"
21
+ require_relative "azure_file_shares/operations/snapshots_operations"
22
+ require_relative "azure_file_shares/operations/file_operations"
23
+
24
+ # Errors
25
+ require_relative "azure_file_shares/errors/api_error"
26
+ require_relative "azure_file_shares/errors/configuration_error"
27
+
28
+ # Main module for Azure File Shares API client
29
+ module AzureFileShares
30
+ class << self
31
+ attr_accessor :configuration
32
+
33
+ # Configure the AzureFileShares client
34
+ # @yield [config] Configuration object
35
+ # @return [AzureFileShares::Configuration]
36
+ def configure
37
+ self.configuration ||= Configuration.new
38
+ yield(configuration) if block_given?
39
+ configuration
40
+ end
41
+
42
+ # Get or create a new client instance
43
+ # @return [AzureFileShares::Client]
44
+ def client
45
+ @client ||= Client.new(configuration)
46
+ end
47
+
48
+ # Reset the configuration
49
+ # @return [AzureFileShares::Configuration]
50
+ def reset
51
+ self.configuration = Configuration.new
52
+ end
53
+ end
54
+ end
metadata ADDED
@@ -0,0 +1,198 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: azure_file_shares
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.5
5
+ platform: ruby
6
+ authors:
7
+ - Dmitry Trager
8
+ bindir: bin
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: faraday
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - "~>"
17
+ - !ruby/object:Gem::Version
18
+ version: '2.7'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - "~>"
24
+ - !ruby/object:Gem::Version
25
+ version: '2.7'
26
+ - !ruby/object:Gem::Dependency
27
+ name: faraday-retry
28
+ requirement: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - "~>"
31
+ - !ruby/object:Gem::Version
32
+ version: '2.0'
33
+ type: :runtime
34
+ prerelease: false
35
+ version_requirements: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '2.0'
40
+ - !ruby/object:Gem::Dependency
41
+ name: jwt
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '2.7'
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '2.7'
54
+ - !ruby/object:Gem::Dependency
55
+ name: nokogiri
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.15'
61
+ type: :runtime
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '1.15'
68
+ - !ruby/object:Gem::Dependency
69
+ name: bundler
70
+ requirement: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '2.0'
75
+ type: :development
76
+ prerelease: false
77
+ version_requirements: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '2.0'
82
+ - !ruby/object:Gem::Dependency
83
+ name: rake
84
+ requirement: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '13.0'
89
+ type: :development
90
+ prerelease: false
91
+ version_requirements: !ruby/object:Gem::Requirement
92
+ requirements:
93
+ - - "~>"
94
+ - !ruby/object:Gem::Version
95
+ version: '13.0'
96
+ - !ruby/object:Gem::Dependency
97
+ name: rspec
98
+ requirement: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - "~>"
101
+ - !ruby/object:Gem::Version
102
+ version: '3.12'
103
+ type: :development
104
+ prerelease: false
105
+ version_requirements: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - "~>"
108
+ - !ruby/object:Gem::Version
109
+ version: '3.12'
110
+ - !ruby/object:Gem::Dependency
111
+ name: rubocop
112
+ requirement: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - "~>"
115
+ - !ruby/object:Gem::Version
116
+ version: '1.50'
117
+ type: :development
118
+ prerelease: false
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - "~>"
122
+ - !ruby/object:Gem::Version
123
+ version: '1.50'
124
+ - !ruby/object:Gem::Dependency
125
+ name: webmock
126
+ requirement: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - "~>"
129
+ - !ruby/object:Gem::Version
130
+ version: '3.18'
131
+ type: :development
132
+ prerelease: false
133
+ version_requirements: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: '3.18'
138
+ - !ruby/object:Gem::Dependency
139
+ name: vcr
140
+ requirement: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: '6.1'
145
+ type: :development
146
+ prerelease: false
147
+ version_requirements: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - "~>"
150
+ - !ruby/object:Gem::Version
151
+ version: '6.1'
152
+ description: A Ruby gem for interacting with the Microsoft Azure File Shares API
153
+ email:
154
+ - dmitry.trager@revealbot.com
155
+ executables: []
156
+ extensions: []
157
+ extra_rdoc_files: []
158
+ files:
159
+ - Readme.md
160
+ - lib/azure_file_shares.rb
161
+ - lib/azure_file_shares/auth/token_provider.rb
162
+ - lib/azure_file_shares/client.rb
163
+ - lib/azure_file_shares/configuration.rb
164
+ - lib/azure_file_shares/errors/api_error.rb
165
+ - lib/azure_file_shares/errors/configuration_error.rb
166
+ - lib/azure_file_shares/operations/base_operation.rb
167
+ - lib/azure_file_shares/operations/file_operations.rb
168
+ - lib/azure_file_shares/operations/file_shares_operations.rb
169
+ - lib/azure_file_shares/operations/snapshots_operations.rb
170
+ - lib/azure_file_shares/resources/file_share.rb
171
+ - lib/azure_file_shares/resources/file_share_snapshot.rb
172
+ - lib/azure_file_shares/version.rb
173
+ homepage: https://github.com/dmitrytrager/azure_file_shares
174
+ licenses:
175
+ - MIT
176
+ metadata:
177
+ homepage_uri: https://github.com/dmitrytrager/azure_file_shares
178
+ source_code_uri: https://github.com/dmitrytrager/azure_file_shares
179
+ changelog_uri: https://github.com/dmitrytrager/azure_file_shares/blob/main/CHANGELOG.md
180
+ documentation_uri: https://github.com/dmitrytrager/azure_file_shares/blob/main/README.md
181
+ rdoc_options: []
182
+ require_paths:
183
+ - lib
184
+ required_ruby_version: !ruby/object:Gem::Requirement
185
+ requirements:
186
+ - - ">="
187
+ - !ruby/object:Gem::Version
188
+ version: 2.6.0
189
+ required_rubygems_version: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - ">="
192
+ - !ruby/object:Gem::Version
193
+ version: '0'
194
+ requirements: []
195
+ rubygems_version: 3.7.1
196
+ specification_version: 4
197
+ summary: Ruby client for Microsoft Azure File Shares API
198
+ test_files: []