diff --git a/.codeclimate.yml b/.codeclimate.yml deleted file mode 100644 index e933594..0000000 --- a/.codeclimate.yml +++ /dev/null @@ -1,23 +0,0 @@ ---- -engines: - duplication: - enabled: true - config: - languages: - - ruby - - javascript - - python - - php - fixme: - enabled: true - rubocop: - enabled: true -ratings: - paths: - - "**.inc" - - "**.js" - - "**.jsx" - - "**.module" - - "**.php" - - "**.py" - - "**.rb" diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..87d8085 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,10 @@ +version: 2 +updates: + - package-ecosystem: bundler + directory: / + schedule: + interval: weekly + - package-ecosystem: github-actions + directory: / + schedule: + interval: weekly diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..cf20dcd --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,50 @@ +name: CI + +on: + push: + branches: [master] + pull_request: + +permissions: + contents: read + +jobs: + test: + name: Test (Ruby ${{ matrix.ruby }}) + runs-on: ubuntu-latest + strategy: + fail-fast: false + matrix: + ruby: ['3.3', '3.4', '4.0'] + steps: + - uses: actions/checkout@v7 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: ${{ matrix.ruby }} + bundler-cache: true + - run: bundle exec rake test + + lint: + name: RuboCop + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v7 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: '4.0' + bundler-cache: true + - run: bundle exec rubocop + + edge: + name: Test against fog-core and fog-xml master + runs-on: ubuntu-latest + continue-on-error: true + env: + BUNDLE_GEMFILE: gemfiles/Gemfile-edge + steps: + - uses: actions/checkout@v7 + - uses: ruby/setup-ruby@v1 + with: + ruby-version: '4.0' + bundler-cache: true + - run: bundle exec rake test diff --git a/.gitignore b/.gitignore index a26f085..eb85b89 100644 --- a/.gitignore +++ b/.gitignore @@ -15,4 +15,6 @@ mkmf.log tests/.fog # RubyMine IDE /.idea -.fog \ No newline at end of file +.fog +*.gem +/gemfiles/*.lock diff --git a/.rubocop.yml b/.rubocop.yml index 2174e87..71503a4 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,4 +1,9 @@ -Metrics/LineLength: +AllCops: + TargetRubyVersion: 3.3 + NewCops: enable + SuggestExtensions: false + +Layout/LineLength: Max: 160 Style/Documentation: diff --git a/.ruby-gemset b/.ruby-gemset deleted file mode 100644 index 3fcf23e..0000000 --- a/.ruby-gemset +++ /dev/null @@ -1 +0,0 @@ -fog-akamai diff --git a/.ruby-version b/.ruby-version index d7edb56..43beb40 100644 --- a/.ruby-version +++ b/.ruby-version @@ -1 +1 @@ -ruby-2.6.5 +4.0.7 diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 910d5cb..0000000 --- a/.travis.yml +++ /dev/null @@ -1,45 +0,0 @@ -nguage: ruby -sudo: false -script: bundle exec rake test -branches: - except: - - "/\\Av\\d+\\Z/" -matrix: - fast_finish: true - include: - - rvm: 1.8.7 - gemfile: gemfiles/Gemfile-ruby-1.8.7 - - rvm: 1.9.3 - gemfile: Gemfile - - rvm: 2.0.0 - gemfile: Gemfile - - rvm: 2.1.0 - gemfile: Gemfile - - rvm: 2.1.1 - gemfile: Gemfile - - rvm: 2.1.1 - gemfile: gemfiles/Gemfile-edge - - rvm: 2.2.0 - gemfile: Gemfile - - rvm: 2.2.0 - gemfile: gemfiles/Gemfile-edge - - rvm: jruby-18mode - gemfile: gemfiles/Gemfile-ruby-1.8.7 - - rvm: jruby-19mode - gemfile: Gemfile - - rvm: jruby-head - gemfile: Gemfile - allow_failures: - - rvm: jruby-head -notifications: - email: false - irc: - channels: - - irc.freenode.org#ruby-fog - template: - - "[#%{build_number}] %{message} %{build_url}" - - "[#%{build_number}] %{commit} on %{branch} by %{author}" - - "[#%{build_number}] %{compare_url}" - on_success: always - on_failure: always - use_notice: false diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..6830e44 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,30 @@ +# Changelog + +## 0.6.0 - Unreleased + +### Breaking + +- Requires Ruby >= 3.3. Older Rubies are no longer supported. +- Requires fog-core ~> 2.1 (was ~> 1.27). The unused fog-json dependency is gone. + +### Changed + +- The service class is now `Fog::Akamai::Storage`, the layout fog-core 2 expects. `Fog::Storage::Akamai` still works as a deprecated alias and will be removed in a future major release. `Fog::Storage.new(provider: 'akamai')` is unchanged. +- The response parsers moved to `Fog::Parsers::Akamai::Storage` (internal API). +- The published gem only contains `lib/`, the README, the license and this changelog. + +### Fixed + +- Request signing no longer depends on `OpenSSL::Digest::Digest` or the `Base64` library, which are gone on current Rubies. +- `CGI.escape` is required explicitly, so `rename` and `symlink` work without a full `cgi`. +- `fog-core` no longer logs two deprecation lines on every `Fog::Storage.new`. +- Uploading a `nil` body raised `NoMethodError` instead of `ArgumentError`. +- `rake test` globbed a non-existent `tests/` directory and ran nothing. + +### Development + +- CI moved from Travis to GitHub Actions (Ruby 3.3, 3.4, 4.0, RuboCop, and fog-core/fog-xml master). +- Code Climate is gone; SimpleCov writes a local coverage report. +- Tests run on minitest 6 and webmock 3; RuboCop is on 1.x. + +Earlier releases are listed on the [GitHub tags](https://github.com/fog/fog-akamai/tags). diff --git a/CLAUDE.md b/CLAUDE.md new file mode 100644 index 0000000..4851fb2 --- /dev/null +++ b/CLAUDE.md @@ -0,0 +1,51 @@ +# CLAUDE.md + +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. + +## Project + +`fog-akamai` is a fog provider gem for Akamai NetStorage (the ObjectStore HTTP API; the spec is in `docs/NS_http_api_FS.pdf`). It implements every NetStorage action except quick-delete, which is left out on purpose. The gem requires Ruby >= 3.3 (`.ruby-version` pins 4.0.7 for development) and depends on fog-core 2.x and fog-xml. Development dependencies (minitest 6, minitest-mock, minitest-reporters, webmock 3, timecop, SimpleCov, RuboCop, rake) live in the `Gemfile`, not the gemspec. + +## Commands + +- Install deps: `bin/setup` (runs `bundle install`) +- Console: `bin/console` +- Tests and lint (the default task, also what CI runs): `bundle exec rake` +- Tests only: `bundle exec rake test` +- Lint: `bundle exec rubocop` (config in `.rubocop.yml`: TargetRubyVersion 3.3, line length 160, Style/Documentation off) +- Run one file: `bundle exec ruby -Itest -Ilib test/fog/akamai/requests/storage/upload_test.rb` +- Run one test: append `-n test_upload` (or `-n /pattern/`) +- Another Ruby: `mise exec ruby@3.3.5 -- bundle exec rake test`. CI runs 3.3, 3.4 and 4.0. +- Against fog-core/fog-xml master: `BUNDLE_GEMFILE=gemfiles/Gemfile-edge bundle exec rake test` + +Tests need `test/` and `lib/` on the load path because they `require 'helpers/...'` and `require 'fog/akamai/storage_test_base'`. The Rakefile and the commands above already set that up. + +Known quirks: + +- On Ruby 4.0, fog-core 2.6.0 itself prints a `CGI library is removed` warning at load time, and a frozen-string-literal warning under `-w`. They come from fog-core, not from this gem. +- `Fog::Storage::Akamai` (the pre-0.6 constant) is a deprecated alias of `Fog::Akamai::Storage` and is meant to be removed in 1.0. +- `symlink` has no Mock implementation (issue #3); in mock mode fog-core raises `Fog::Errors::MockNotImplemented`. +- Model gaps: `File#get` and `File#destroy` are stubs that don't call the service yet, and `Files#all` returns `directory.files`. + +## Architecture + +The gem follows the standard fog provider layout, using the fog-core 2 `Fog::::` namespace: + +- `lib/fog/akamai.rb` registers the `Fog::Akamai` provider with a `:storage` service and autoloads `Fog::Akamai::Storage` (the autoload is what stops fog-core logging a deprecation on every `Fog::Storage.new`). `Fog::Akamai::Shared#full_path` joins a directory key and a path; models use it. +- `lib/fog/akamai/storage.rb` defines `Fog::Akamai::Storage < Fog::Service`, plus the deprecated `Fog::Storage::Akamai` alias at the bottom: + - Required credentials: `akamai_host`, `akamai_key_name`, `akamai_key`, `akamai_cp_code` (usually from `~/.fog`). Optional: `scheme`/`port` (defaults https/443). + - `Helpers#format_path` prefixes every path with `/`. Request methods take paths *without* the CP code; models strip it when building keys. + - `Real#request` signs every call with the ACS headers (`X-Akamai-ACS-Auth-Data`, `-Auth-Sign` = Base64 HMAC-SHA256 over auth data + path + action, `-Action`). Each action must be listed in `VALID_ACTIONS`, or `acs_action` raises. + - `Mock` keeps an in-memory class-level hash, `data`, keyed by the full `//path`. Each value is `{ directory:, files: [], directories: [] }`, and file contents are stored at their own keys. +- `requests/storage/.rb`: each file reopens `Real` and `Mock` and adds one method named after the NetStorage action (dir, mkdir, upload, download, stat, delete, du, mtime, rename, rmdir, symlink). **When adding an action**, add the file, register it with `request :name` in `storage.rb`, add it to `VALID_ACTIONS`, and implement both Real and Mock. +- `parsers/storage/` holds SAX parsers (`Fog::Parsers::Base`, namespaced `Fog::Parsers::Akamai::Storage`) for the XML responses. `Dir` handles both `dir` and `stat`, and splits `` entries into `:files` and `:directories`. +- `models/storage/`: `Directories#get` calls `dir` and hydrates a `Directory` along with its `files` and `directories` sub-collections. `File#save` → `upload`, `touch` → `mtime`, `rename` → `rename`. `Files#get` → `download`, `stat` → `stat` (returns nil on 404). + +## Tests + +- Test framework: Minitest 6. `test/test_helper.rb` starts SimpleCov, requires `minitest/mock` (used for `Time.stub`/`SecureRandom.stub`) and auto-requires `test/support/*`, which set fake credentials (host `example-nsu.akamai.net`, cp_code `42`), enable webmock and use the minitest-reporters. +- `test/fog/akamai/storage_test_base.rb` defines two base classes: + - `StorageTestBase`: real mode. HTTP is stubbed with the webmock helpers in `test/helpers/_request_stub.rb` (stubbed paths include `/42`). + - `MockStorageTestBase`: calls `Fog.mock!` and resets the mock data in teardown. +- Request tests usually define one class of each kind per action. Time-dependent mock assertions use `Timecop.freeze`. +- `test/fog/akamai_test.rb` covers provider loading: the namespace, no deprecation output (one test spawns a subprocess to check the load-time output), and the deprecated alias. diff --git a/Gemfile b/Gemfile index ef15124..1f39d83 100644 --- a/Gemfile +++ b/Gemfile @@ -1,6 +1,17 @@ +# frozen_string_literal: true + source 'https://rubygems.org' -# Specify your gem's dependencies in fog-netstorage.gemspec +# Runtime dependencies live in fog-akamai.gemspec gemspec -gem 'codeclimate-test-reporter', group: :test, require: nil +group :development, :test do + gem 'minitest', '~> 6.0' + gem 'minitest-mock', '~> 5.27' + gem 'minitest-reporters', '~> 1.8' + gem 'rake', '~> 13.0' + gem 'rubocop', '~> 1.92', require: false + gem 'simplecov', '~> 1.3', require: false + gem 'timecop', '~> 0.9' + gem 'webmock', '~> 3.29' +end diff --git a/README.md b/README.md index f300efb..c957c2a 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,12 @@ -[![Code Climate](https://codeclimate.com/github/alexandru-calinoiu/fog-akamai/badges/gpa.svg)](https://codeclimate.com/github/fog/fog-akamai) - -[![Test Coverage](https://codeclimate.com/github/alexandru-calinoiu/fog-akamai/badges/coverage.svg)](https://codeclimate.com/github/fog/fog-akamai/coverage) +[![CI](https://github.com/fog/fog-akamai/actions/workflows/ci.yml/badge.svg)](https://github.com/fog/fog-akamai/actions/workflows/ci.yml) # Fog Akamai -Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/fog/storage`. To experiment with that code, run `bin/console` for an interactive prompt. +A [fog](https://github.com/fog/fog) provider for Akamai NetStorage, built on the ObjectStore HTTP API (the spec is in `docs/NS_http_api_FS.pdf`). + +All the functionality of the NetStorage API is implemented except the really dangerous bit, quick-delete. -All the functionality of the net storage api is implemented except the really dangerous bit, quick-delete. +Requires Ruby 3.3 or newer and fog-core 2.x. ## Installation @@ -47,7 +47,19 @@ You can get more detail about how to obtain this credential form [this doc](http ### Connecting to NetStorage service ```ruby -net_storage = Fog::Compute.new :provider => 'akamai' +net_storage = Fog::Storage.new(provider: 'akamai') +``` + +You can also pass the credentials explicitly: + +```ruby +net_storage = Fog::Storage.new( + provider: 'akamai', + akamai_host: '', + akamai_key_name: '', + akamai_key: '', + akamai_cp_code: '' +) ``` ### To get a directory: @@ -68,17 +80,20 @@ directory.files.stat('file.ext') directory.files.create(directory: directory, body: file_body, key: file_name) ``` +### Upgrading from 0.5 + +The service class is now `Fog::Akamai::Storage`. `Fog::Storage::Akamai` still works but is deprecated and will be removed in a future major release. If you only use `Fog::Storage.new(provider: 'akamai')` nothing changes. See the [changelog](CHANGELOG.md) for the other changes. + ## Roadmap - implement ccu api ## Development -After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment. +After checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rake` to run the tests and RuboCop (`bundle exec rake test` runs only the tests). You can also run `bin/console` for an interactive prompt that will allow you to experiment. -To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). +To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb` and the changelog, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org). ## Contributing -Bug reports and pull requests are welcome on GitHub at https://github.com/alexandru-calinoiu/fog-akamai. - +Bug reports and pull requests are welcome on GitHub at https://github.com/fog/fog-akamai. diff --git a/Rakefile b/Rakefile index 4439e99..f99c8df 100644 --- a/Rakefile +++ b/Rakefile @@ -1,11 +1,16 @@ +# frozen_string_literal: true + require 'bundler/gem_tasks' require 'rake/testtask' +require 'rubocop/rake_task' Rake::TestTask.new do |t| - t.libs.push %w(tests) - t.test_files = FileList['tests/**/*_test.rb'] + t.libs.push %w[test lib] + t.test_files = FileList['test/**/*_test.rb'] t.verbose = true end +RuboCop::RakeTask.new + desc 'Default Task' -task default: [:test] +task default: %i[test rubocop] diff --git a/bin/console b/bin/console index b026d8b..b39294e 100755 --- a/bin/console +++ b/bin/console @@ -1,4 +1,5 @@ #!/usr/bin/env ruby +# frozen_string_literal: true require 'bundler/setup' require 'fog/akamai' diff --git a/fog-akamai.gemspec b/fog-akamai.gemspec index a2da619..9633b24 100644 --- a/fog-akamai.gemspec +++ b/fog-akamai.gemspec @@ -1,5 +1,6 @@ -# coding: utf-8 -lib = File.expand_path('../lib', __FILE__) +# frozen_string_literal: true + +lib = File.expand_path('lib', __dir__) $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib) require 'fog/akamai/version' @@ -11,25 +12,20 @@ Gem::Specification.new do |spec| spec.license = 'MIT' spec.summary = "Module for 'fog' gem to support Akamai" - spec.description = 'This library can be used as a module for `fog` or as standalone provider - to use Akamai' - spec.homepage = 'https://github.com/alexandru-calinoiu/fog-akamai' + spec.description = 'This library can be used as a module for `fog` or as standalone provider to use Akamai NetStorage' + spec.homepage = 'https://github.com/fog/fog-akamai' - spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) } - spec.bindir = 'exe' - spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) } - spec.require_paths = ['lib'] + spec.metadata = { + 'changelog_uri' => "#{spec.homepage}/blob/master/CHANGELOG.md", + 'bug_tracker_uri' => "#{spec.homepage}/issues", + 'rubygems_mfa_required' => 'true' + } - spec.add_development_dependency 'bundler', '~> 2.0' - spec.add_development_dependency 'rake', '>= 12.3.3' - spec.add_development_dependency 'minitest', '~> 5.8' - spec.add_development_dependency 'minitest-reporters', '~> 1.1' - spec.add_development_dependency 'test-unit', '~> 3.1' - spec.add_development_dependency 'webmock', '~> 1.22' - spec.add_development_dependency 'rubocop', '~> 0.49' - spec.add_development_dependency 'timecop', '~> 0.8.0' + spec.required_ruby_version = '>= 3.3' + + spec.files = Dir['lib/**/*.rb', 'README.md', 'LICENSE.md', 'CHANGELOG.md'] + spec.require_paths = ['lib'] - spec.add_dependency 'fog-core', '~> 1.27' - spec.add_dependency 'fog-json', '~> 1.0' - spec.add_dependency 'fog-xml', '~> 0.1' + spec.add_dependency 'fog-core', '~> 2.1' + spec.add_dependency 'fog-xml', '~> 0.1' end diff --git a/gemfiles/Gemfile-edge b/gemfiles/Gemfile-edge index 0a6c200..347e956 100644 --- a/gemfiles/Gemfile-edge +++ b/gemfiles/Gemfile-edge @@ -1,10 +1,16 @@ -source "https://rubygems.org" +source 'https://rubygems.org' # Shared components -gem "fog-core", :github => "fog/fog-core" -gem "fog-json", :github => "fog/fog-json" +gem 'fog-core', github: 'fog/fog-core' +gem 'fog-xml', github: 'fog/fog-xml' -gem "codeclimate-test-reporter", group: :test, require: nil - -gemspec :path => "../" +gemspec path: '../' +gem 'minitest', '~> 6.0' +gem 'minitest-mock', '~> 5.27' +gem 'minitest-reporters', '~> 1.8' +gem 'rake', '~> 13.0' +gem 'rubocop', '~> 1.92', require: false +gem 'simplecov', '~> 1.3', require: false +gem 'timecop', '~> 0.9' +gem 'webmock', '~> 3.29' diff --git a/gemfiles/Gemfile-ruby-1.8.7 b/gemfiles/Gemfile-ruby-1.8.7 deleted file mode 100644 index 8d96f0a..0000000 --- a/gemfiles/Gemfile-ruby-1.8.7 +++ /dev/null @@ -1,7 +0,0 @@ -source "https://rubygems.org" - -gem 'mime-types', '~> 1.16' -gem 'nokogiri', '~> 1.5.11' - -gemspec :path => "../" - diff --git a/lib/fog/akamai.rb b/lib/fog/akamai.rb index f6e3909..5c1b1c3 100644 --- a/lib/fog/akamai.rb +++ b/lib/fog/akamai.rb @@ -1,15 +1,15 @@ +# frozen_string_literal: true + require 'fog/core' require 'fog/xml' require 'fog/akamai/version' module Fog - module Storage - autoload :Akamai, 'fog/akamai/storage' - end - module Akamai extend Fog::Provider + autoload :Storage, 'fog/akamai/storage' + service(:storage, 'Storage') module Shared @@ -19,4 +19,9 @@ def full_path(path, directory = nil) end end end + + module Storage + # Deprecated: use Fog::Akamai::Storage. The alias is defined in fog/akamai/storage. + autoload :Akamai, 'fog/akamai/storage' + end end diff --git a/lib/fog/akamai/models/storage/directories.rb b/lib/fog/akamai/models/storage/directories.rb index 4b1caa2..5a98248 100644 --- a/lib/fog/akamai/models/storage/directories.rb +++ b/lib/fog/akamai/models/storage/directories.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + module Fog - module Storage - class Akamai + module Akamai + class Storage class Directories < Fog::Collection - model Fog::Storage::Akamai::Directory + model Fog::Akamai::Storage::Directory attribute :parent diff --git a/lib/fog/akamai/models/storage/directory.rb b/lib/fog/akamai/models/storage/directory.rb index 2021ad7..8236430 100644 --- a/lib/fog/akamai/models/storage/directory.rb +++ b/lib/fog/akamai/models/storage/directory.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + module Fog - module Storage - class Akamai + module Akamai + class Storage class Directory < Fog::Model include Fog::Akamai::Shared @@ -11,14 +13,14 @@ class Directory < Fog::Model attribute :mtime def files - @files ||= Fog::Storage::Akamai::Files.new( + @files ||= Fog::Akamai::Storage::Files.new( directory: self, service: service ) end def directories - @directories ||= Fog::Storage::Akamai::Directories.new( + @directories ||= Fog::Akamai::Storage::Directories.new( parent: self, service: service ) diff --git a/lib/fog/akamai/models/storage/file.rb b/lib/fog/akamai/models/storage/file.rb index 00185ff..6f42bc1 100644 --- a/lib/fog/akamai/models/storage/file.rb +++ b/lib/fog/akamai/models/storage/file.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + module Fog - module Storage - class Akamai + module Akamai + class Storage class File < Fog::Model include Fog::Akamai::Shared @@ -30,7 +32,7 @@ def ready? true end - def touch(mtime = DateTime.now.to_time.to_i) + def touch(mtime = Time.now.to_i) requires :directory, :key service.mtime(full_path(key, directory), mtime) end diff --git a/lib/fog/akamai/models/storage/files.rb b/lib/fog/akamai/models/storage/files.rb index d52a0e9..711a920 100644 --- a/lib/fog/akamai/models/storage/files.rb +++ b/lib/fog/akamai/models/storage/files.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + module Fog - module Storage - class Akamai + module Akamai + class Storage class Files < Fog::Collection include Fog::Akamai::Shared - model Fog::Storage::Akamai::File + model Fog::Akamai::Storage::File attribute :directory diff --git a/lib/fog/akamai/parsers/storage/dir.rb b/lib/fog/akamai/parsers/storage/dir.rb index 482ad09..29948b3 100644 --- a/lib/fog/akamai/parsers/storage/dir.rb +++ b/lib/fog/akamai/parsers/storage/dir.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + module Fog module Parsers - module Storage - module Akamai + module Akamai + module Storage class Dir < Fog::Parsers::Base def reset @response = { directory: '', files: [], directories: [] } diff --git a/lib/fog/akamai/parsers/storage/du.rb b/lib/fog/akamai/parsers/storage/du.rb index b101e9b..37f314e 100644 --- a/lib/fog/akamai/parsers/storage/du.rb +++ b/lib/fog/akamai/parsers/storage/du.rb @@ -1,7 +1,9 @@ +# frozen_string_literal: true + module Fog module Parsers - module Storage - module Akamai + module Akamai + module Storage class Du < Fog::Parsers::Base def reset @response = { directory: '', files: '', bytes: '' } diff --git a/lib/fog/akamai/requests/storage/delete.rb b/lib/fog/akamai/requests/storage/delete.rb index c16ad9c..97a30d3 100644 --- a/lib/fog/akamai/requests/storage/delete.rb +++ b/lib/fog/akamai/requests/storage/delete.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + require 'pathname' module Fog - module Storage - class Akamai + module Akamai + class Storage class Real # Use this action to delete an individual file or symbolic link. # @param path [String] the path for the file that will be downloaded @@ -21,11 +23,9 @@ class Mock def delete(path) path_guard(path) - if remove_file(Pathname.new(format_path(path))) - Excon::Response.new(status: 200) - else - fail(Excon::Errors::NotFound, '404 Not Found') - end + raise(Excon::Errors::NotFound, '404 Not Found') unless remove_file(Pathname.new(format_path(path))) + + Excon::Response.new(status: 200) end private diff --git a/lib/fog/akamai/requests/storage/dir.rb b/lib/fog/akamai/requests/storage/dir.rb index 93fd451..47c070b 100644 --- a/lib/fog/akamai/requests/storage/dir.rb +++ b/lib/fog/akamai/requests/storage/dir.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + module Fog - module Storage - class Akamai + module Akamai + class Storage class Real require 'fog/akamai/parsers/storage/dir' @@ -24,14 +26,14 @@ def dir(path = '') path: format_path(path), method: 'GET', expects: 200, - parser: Fog::Parsers::Storage::Akamai::Dir.new) + parser: Fog::Parsers::Akamai::Storage::Dir.new) end end class Mock def dir(path = '') key = format_path(path) - data.key?(key) ? Excon::Response.new(status: 200, body: data[key]) : fail(Excon::Errors::NotFound, '404 Not Found') + data.key?(key) ? Excon::Response.new(status: 200, body: data[key]) : raise(Excon::Errors::NotFound, '404 Not Found') end end end diff --git a/lib/fog/akamai/requests/storage/download.rb b/lib/fog/akamai/requests/storage/download.rb index d8b14fc..c7a1858 100644 --- a/lib/fog/akamai/requests/storage/download.rb +++ b/lib/fog/akamai/requests/storage/download.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + module Fog - module Storage - class Akamai + module Akamai + class Storage class Real # Use this action to download a file # @param path [String] the path for the file that will be downloaded @@ -20,7 +22,8 @@ class Mock def download(path) path_guard(path) formatted_path = format_path(path) - fail(Excon::Errors::NotFound, '404 Not Found') unless data.key?(formatted_path) && data[formatted_path].key?(:body) + raise(Excon::Errors::NotFound, '404 Not Found') unless data.key?(formatted_path) && data[formatted_path].key?(:body) + Excon::Response.new(status: 200, body: data[formatted_path][:body]) end end diff --git a/lib/fog/akamai/requests/storage/du.rb b/lib/fog/akamai/requests/storage/du.rb index deda82f..7055c2f 100644 --- a/lib/fog/akamai/requests/storage/du.rb +++ b/lib/fog/akamai/requests/storage/du.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + module Fog - module Storage - class Akamai + module Akamai + class Storage class Real require 'fog/akamai/parsers/storage/du' @@ -19,7 +21,7 @@ def du(path) path: format_path(path), method: 'GET', expects: 200, - parser: Fog::Parsers::Storage::Akamai::Du.new) + parser: Fog::Parsers::Akamai::Storage::Du.new) end end @@ -30,11 +32,9 @@ def du(path) key = format_path(path) directory = data[key] - if directory - Excon::Response.new(status: 200, body: { directory: key, files: directory[:files].count.to_s, bytes: directory[:directories].count.to_s }) - else - fail(Excon::Errors::NotFound, '404 Not Found') - end + raise(Excon::Errors::NotFound, '404 Not Found') unless directory + + Excon::Response.new(status: 200, body: { directory: key, files: directory[:files].count.to_s, bytes: directory[:directories].count.to_s }) end end end diff --git a/lib/fog/akamai/requests/storage/mkdir.rb b/lib/fog/akamai/requests/storage/mkdir.rb index 80b09a7..2caa83b 100644 --- a/lib/fog/akamai/requests/storage/mkdir.rb +++ b/lib/fog/akamai/requests/storage/mkdir.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + require 'pathname' module Fog - module Storage - class Akamai + module Akamai + class Storage class Real # Use this action to create a dir # @param path [String] the path to create, it will create directories recursively @@ -13,8 +15,7 @@ def mkdir(path) request(:mkdir, path: format_path(path), method: 'PUT', - expects: 200 - ) + expects: 200) end end @@ -44,7 +45,7 @@ def update_data(key, last_path_basename) end def build_directory_node(last_path_basename) - { 'type' => 'dir', 'name' => last_path_basename, 'mtime' => DateTime.now.to_time.to_i.to_s } + { 'type' => 'dir', 'name' => last_path_basename, 'mtime' => Time.now.to_i.to_s } end end end diff --git a/lib/fog/akamai/requests/storage/mtime.rb b/lib/fog/akamai/requests/storage/mtime.rb index 54dcc5f..90bfc68 100644 --- a/lib/fog/akamai/requests/storage/mtime.rb +++ b/lib/fog/akamai/requests/storage/mtime.rb @@ -1,15 +1,17 @@ +# frozen_string_literal: true + require 'pathname' module Fog - module Storage - class Akamai + module Akamai + class Storage class Real # Use this action to change a file's modification time ("touch"). # @param path [String] the path for he file that will be downloaded # @param mtime [int] the desired modification time for the target content (i.e., in UNIX epoch time). # @return [Excon::Response] response - def mtime(path, mtime = DateTime.now.to_time.to_i) + def mtime(path, mtime = Time.now.to_i) path_guard(path) request({ action: :mtime, mtime: mtime }, path: format_path(path), @@ -19,18 +21,16 @@ def mtime(path, mtime = DateTime.now.to_time.to_i) end class Mock - def mtime(path, mtime = DateTime.now.to_time.to_i) + def mtime(path, mtime = Time.now.to_i) path_guard(path) pathname = Pathname.new(format_path(path)) file = get_file(pathname) - if file - file['mtime'] = mtime.to_s - Excon::Response.new(status: 200) - else - fail(Excon::Errors::NotFound, '404 Not Found') - end + raise(Excon::Errors::NotFound, '404 Not Found') unless file + + file['mtime'] = mtime.to_s + Excon::Response.new(status: 200) end private diff --git a/lib/fog/akamai/requests/storage/rename.rb b/lib/fog/akamai/requests/storage/rename.rb index cf17d3a..1767416 100644 --- a/lib/fog/akamai/requests/storage/rename.rb +++ b/lib/fog/akamai/requests/storage/rename.rb @@ -1,8 +1,11 @@ +# frozen_string_literal: true + +require 'cgi/escape' require 'pathname' module Fog - module Storage - class Akamai + module Akamai + class Storage class Real # Use this action to rename a file or symbolic link. # @param source [String] the path to check @@ -28,12 +31,10 @@ def rename(source, destination) source_pathname = Pathname.new(format_path(source)) destination_pathname = Pathname.new(format_path(destination)) - if rename_file(source_pathname, destination_pathname) - move_file(source_pathname, destination_pathname) - Excon::Response.new(status: 200) - else - fail(Excon::Errors::NotFound, '404 Not Found') - end + raise(Excon::Errors::NotFound, '404 Not Found') unless rename_file(source_pathname, destination_pathname) + + move_file(source_pathname, destination_pathname) + Excon::Response.new(status: 200) end private diff --git a/lib/fog/akamai/requests/storage/rmdir.rb b/lib/fog/akamai/requests/storage/rmdir.rb index fe2b6ec..015fbad 100644 --- a/lib/fog/akamai/requests/storage/rmdir.rb +++ b/lib/fog/akamai/requests/storage/rmdir.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + module Fog - module Storage - class Akamai + module Akamai + class Storage class Real # Use this action to delete an empty directory. # @param path [String] the path to the directory @@ -22,12 +24,10 @@ def rmdir(path) formatted_path = format_path(path) dir = data[formatted_path] - if empty?(dir) - data.delete(formatted_path) - Excon::Response.new(status: 200) - else - fail(Excon::Errors::Conflict, 'Not a empty directory') - end + raise(Excon::Errors::Conflict, 'Not a empty directory') unless empty?(dir) + + data.delete(formatted_path) + Excon::Response.new(status: 200) end private diff --git a/lib/fog/akamai/requests/storage/stat.rb b/lib/fog/akamai/requests/storage/stat.rb index dd20c78..dee5fbe 100644 --- a/lib/fog/akamai/requests/storage/stat.rb +++ b/lib/fog/akamai/requests/storage/stat.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + require 'pathname' module Fog - module Storage - class Akamai + module Akamai + class Storage class Real require 'fog/akamai/parsers/storage/dir' @@ -28,7 +30,7 @@ def stat(path) path: format_path(path), method: 'GET', expects: 200, - parser: Fog::Parsers::Storage::Akamai::Dir.new) + parser: Fog::Parsers::Akamai::Storage::Dir.new) end end @@ -41,7 +43,8 @@ def stat(path) response = Excon::Response.new(status: get_status(key, path.basename.to_s), body: get_body(key)) - fail(Excon::Errors::NotFound, '404 Not Found') if response.status == 404 + raise(Excon::Errors::NotFound, '404 Not Found') if response.status == 404 + response end diff --git a/lib/fog/akamai/requests/storage/symlink.rb b/lib/fog/akamai/requests/storage/symlink.rb index 746d145..62e3df9 100644 --- a/lib/fog/akamai/requests/storage/symlink.rb +++ b/lib/fog/akamai/requests/storage/symlink.rb @@ -1,6 +1,10 @@ +# frozen_string_literal: true + +require 'cgi/escape' + module Fog - module Storage - class Akamai + module Akamai + class Storage class Real # Use this action to rename a file or symbolic link. # @param source [String] the path to check @@ -18,8 +22,8 @@ def symlink(source, target) end end - class Mock - end + # There is no Mock#symlink yet, so fog-core raises Fog::Errors::MockNotImplemented in mock mode. + # See https://github.com/fog/fog-akamai/issues/3 end end end diff --git a/lib/fog/akamai/requests/storage/upload.rb b/lib/fog/akamai/requests/storage/upload.rb index 56e79a8..2dcf019 100644 --- a/lib/fog/akamai/requests/storage/upload.rb +++ b/lib/fog/akamai/requests/storage/upload.rb @@ -1,8 +1,10 @@ +# frozen_string_literal: true + require 'pathname' module Fog - module Storage - class Akamai + module Akamai + class Storage class Real # Use this action to upload a file # @param path [String] the path to where to upload @@ -43,7 +45,7 @@ def add_file(dir, path, body) end def build_file(body, path) - { 'type' => 'file', 'name' => path.basename.to_s, 'mtime' => DateTime.now.to_time.to_i.to_s, 'size' => body.size.to_s } + { 'type' => 'file', 'name' => path.basename.to_s, 'mtime' => Time.now.to_i.to_s, 'size' => body.size.to_s } end end end diff --git a/lib/fog/akamai/storage.rb b/lib/fog/akamai/storage.rb index 8ac73b2..3da11a7 100644 --- a/lib/fog/akamai/storage.rb +++ b/lib/fog/akamai/storage.rb @@ -1,9 +1,14 @@ +# frozen_string_literal: true + +require 'openssl' +require 'securerandom' + module Fog - module Storage - class Akamai < Fog::Service + module Akamai + class Storage < Fog::Service requires :akamai_host, :akamai_key_name, :akamai_key, :akamai_cp_code - VALID_ACTIONS = [:dir, :mkdir, :download, :stat, :upload, :delete, :du, :mtime, :rename, :rmdir, :symlink] + VALID_ACTIONS = %i[dir mkdir download stat upload delete du mtime rename rmdir symlink].freeze ACS_AUTH_DATA_HEADER = 'X-Akamai-ACS-Auth-Data' ACS_AUTH_SIGN_HEADER = 'X-Akamai-ACS-Auth-Sign' ACS_AUTH_ACTION_HEADER = 'X-Akamai-ACS-Action' @@ -34,11 +39,11 @@ def format_path(path) def path_and_body_guard(path, body) path_guard(path) - fail ArgumentError('body is required') if body.nil? + raise(ArgumentError, 'body is required') if body.nil? end def path_guard(path) - fail(ArgumentError, 'path needs to have a value') if path.nil? || path.empty? + raise(ArgumentError, 'path needs to have a value') if path.nil? || path.empty? end end @@ -92,7 +97,8 @@ class Real # :akamai_key and :akamai_cp_code in order to create a connection # # ==== Examples - # akamai_storage = Storage.new( + # akamai_storage = Fog::Storage.new( + # :provider => 'akamai', # :akamai_host => your_akamai_host_name, # :akamai_key_name => you_akamai_key_name, # :akamai_key => you_akamai_key, @@ -120,15 +126,15 @@ def acs_auth_data def acs_action(action) action = { action: action } if action.is_a?(Symbol) - fail(ArgumentError, "Invalid action #{action} valid actions are: #{VALID_ACTIONS}") unless VALID_ACTIONS.include?(action[:action]) + raise(ArgumentError, "Invalid action #{action} valid actions are: #{VALID_ACTIONS}") unless VALID_ACTIONS.include?(action[:action]) "version=1&#{action.map { |v, k| "#{v}=#{k}" }.join('&')}&format=xml" end def acs_auth_sign(auth_data, path, action) data = auth_data + sign_string(path, action) - digest = OpenSSL::Digest::Digest::SHA256.new - Base64.encode64(OpenSSL::HMAC.digest(digest, akamai_key, data)).strip + digest = OpenSSL::Digest.new('SHA256') + [OpenSSL::HMAC.digest(digest, akamai_key, data)].pack('m0') end private @@ -156,4 +162,10 @@ def sign_string(path, action) end end end + + module Storage + # Deprecated alias for the pre-0.6 constant name; use Fog::Akamai::Storage. + Akamai = Fog::Akamai::Storage + deprecate_constant :Akamai + end end diff --git a/lib/fog/akamai/version.rb b/lib/fog/akamai/version.rb index afba669..9891d14 100644 --- a/lib/fog/akamai/version.rb +++ b/lib/fog/akamai/version.rb @@ -1,5 +1,7 @@ +# frozen_string_literal: true + module Fog module Akamai - VERSION = '0.5.2' + VERSION = '0.6.0' end end diff --git a/test/fog/akamai/models/storage/directories_test.rb b/test/fog/akamai/models/storage/directories_test.rb index 43076c5..c1b6be5 100644 --- a/test/fog/akamai/models/storage/directories_test.rb +++ b/test/fog/akamai/models/storage/directories_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' require 'helpers/dir_request_stub' require 'fog/akamai/storage_test_base' diff --git a/test/fog/akamai/models/storage/directory_test.rb b/test/fog/akamai/models/storage/directory_test.rb index 3eb9de8..9b778a7 100644 --- a/test/fog/akamai/models/storage/directory_test.rb +++ b/test/fog/akamai/models/storage/directory_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' require 'helpers/dir_request_stub' require 'helpers/rmdir_request_stub' diff --git a/test/fog/akamai/models/storage/file_test.rb b/test/fog/akamai/models/storage/file_test.rb index df5d9f6..d41354c 100644 --- a/test/fog/akamai/models/storage/file_test.rb +++ b/test/fog/akamai/models/storage/file_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' require 'helpers/dir_request_stub' require 'helpers/upload_request_stub' @@ -17,11 +19,12 @@ def test_save stub_dir('/42/path') stub_upload = stub_upload('/42/path/test2.jpg') - body = File.open(File.expand_path('../../../../.../../../assets/test2.jpg', __FILE__)) - storage.directories.get('/path').files.create( - key: 'test2.jpg', - body: body - ) + File.open(File.expand_path('../../../.../../../assets/test2.jpg', __dir__)) do |body| + storage.directories.get('/path').files.create( + key: 'test2.jpg', + body: body + ) + end assert_requested stub_upload end diff --git a/test/fog/akamai/models/storage/files_test.rb b/test/fog/akamai/models/storage/files_test.rb index 8f258b7..877b1b1 100644 --- a/test/fog/akamai/models/storage/files_test.rb +++ b/test/fog/akamai/models/storage/files_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' require 'helpers/download_request_stub' require 'helpers/dir_request_stub' @@ -17,7 +19,7 @@ class FilesTest < StorageTestBase def setup super - @file = File.read(File.expand_path('../../../../.../../../assets/test2.jpg', __FILE__)) + @file = File.read(File.expand_path('../../../.../../../assets/test2.jpg', __dir__)) end def test_get diff --git a/test/fog/akamai/requests/storage/delete_test.rb b/test/fog/akamai/requests/storage/delete_test.rb index 24b734b..9753dad 100644 --- a/test/fog/akamai/requests/storage/delete_test.rb +++ b/test/fog/akamai/requests/storage/delete_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' require 'helpers/delete_request_stub' require 'fog/akamai/storage_test_base' diff --git a/test/fog/akamai/requests/storage/dir_test.rb b/test/fog/akamai/requests/storage/dir_test.rb index 2d3d77d..ceac126 100644 --- a/test/fog/akamai/requests/storage/dir_test.rb +++ b/test/fog/akamai/requests/storage/dir_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' require 'helpers/dir_request_stub' require 'fog/akamai/storage_test_base' diff --git a/test/fog/akamai/requests/storage/download_test.rb b/test/fog/akamai/requests/storage/download_test.rb index b9244ac..7f65eb6 100644 --- a/test/fog/akamai/requests/storage/download_test.rb +++ b/test/fog/akamai/requests/storage/download_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' require 'helpers/download_request_stub' require 'fog/akamai/storage_test_base' @@ -20,11 +22,8 @@ def test_download_will_raise_exception_if_status_is_not_ok end class MockDownloadTest < MockStorageTestBase - attr_reader :body - - def setup - super - @body ||= File.open(File.expand_path('../../../../.../../../assets/test2.jpg', __FILE__)) + def body + @body ||= File.open(File.expand_path('../../../.../../../assets/test2.jpg', __dir__)) end def test_with_a_uploaded_file diff --git a/test/fog/akamai/requests/storage/du_test.rb b/test/fog/akamai/requests/storage/du_test.rb index 7e91bc5..6194704 100644 --- a/test/fog/akamai/requests/storage/du_test.rb +++ b/test/fog/akamai/requests/storage/du_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' require 'helpers/du_request_stub' require 'fog/akamai/storage_test_base' diff --git a/test/fog/akamai/requests/storage/mkdir_test.rb b/test/fog/akamai/requests/storage/mkdir_test.rb index be0ec0f..e915202 100644 --- a/test/fog/akamai/requests/storage/mkdir_test.rb +++ b/test/fog/akamai/requests/storage/mkdir_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' require 'helpers/mkdir_request_stub' require 'timecop' diff --git a/test/fog/akamai/requests/storage/mtime_test.rb b/test/fog/akamai/requests/storage/mtime_test.rb index e9b2dbe..c94ca3e 100644 --- a/test/fog/akamai/requests/storage/mtime_test.rb +++ b/test/fog/akamai/requests/storage/mtime_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' require 'helpers/mtime_request_stub' require 'fog/akamai/storage_test_base' diff --git a/test/fog/akamai/requests/storage/rename_test.rb b/test/fog/akamai/requests/storage/rename_test.rb index c6d7d4c..63b94c6 100644 --- a/test/fog/akamai/requests/storage/rename_test.rb +++ b/test/fog/akamai/requests/storage/rename_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' require 'helpers/rename_request_stub' require 'fog/akamai/storage_test_base' diff --git a/test/fog/akamai/requests/storage/rmdir_test.rb b/test/fog/akamai/requests/storage/rmdir_test.rb index e37ae48..8600ea2 100644 --- a/test/fog/akamai/requests/storage/rmdir_test.rb +++ b/test/fog/akamai/requests/storage/rmdir_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' require 'helpers/rmdir_request_stub' require 'fog/akamai/storage_test_base' @@ -21,7 +23,7 @@ def test_rmdir_of_an_empty_dir assert_nil storage.data['/42/path'] end - def test_rmdir_with_a_not_empty_dir_will_raise_request_conflict_409 + def test_rmdir_with_a_not_empty_dir_will_raise_request_conflict storage.upload('/path/dream.mkv', 'clocks') assert_raises(Excon::Errors::Conflict) { storage.rmdir('/path') } end diff --git a/test/fog/akamai/requests/storage/stat_test.rb b/test/fog/akamai/requests/storage/stat_test.rb index 69fb0f1..a46a7a4 100644 --- a/test/fog/akamai/requests/storage/stat_test.rb +++ b/test/fog/akamai/requests/storage/stat_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' require 'helpers/stat_request_stub' require 'fog/akamai/storage_test_base' diff --git a/test/fog/akamai/requests/storage/symlink_test.rb b/test/fog/akamai/requests/storage/symlink_test.rb index 0e3afa7..1b1255d 100644 --- a/test/fog/akamai/requests/storage/symlink_test.rb +++ b/test/fog/akamai/requests/storage/symlink_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' require 'helpers/symlink_request_stub' require 'fog/akamai/storage_test_base' diff --git a/test/fog/akamai/requests/storage/upload_test.rb b/test/fog/akamai/requests/storage/upload_test.rb index c81d9d2..0c2aa66 100644 --- a/test/fog/akamai/requests/storage/upload_test.rb +++ b/test/fog/akamai/requests/storage/upload_test.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' require 'helpers/upload_request_stub' require 'timecop' @@ -7,7 +9,7 @@ module Fog module Storage module UploadTestHelper def body - @body ||= File.open(File.expand_path('../../../../.../../../assets/test2.jpg', __FILE__)) + @body ||= File.open(File.expand_path('../../../.../../../assets/test2.jpg', __dir__)) end end @@ -20,6 +22,11 @@ def test_upload storage.upload('/path/test2.jpg', body) assert_requested stub_upload end + + def test_upload_requires_a_body + error = assert_raises(ArgumentError) { storage.upload('/path/test2.jpg', nil) } + assert_equal 'body is required', error.message + end end class MockUploadTest < MockStorageTestBase diff --git a/test/fog/akamai/storage_test.rb b/test/fog/akamai/storage_test.rb index cb900e9..d1ab727 100644 --- a/test/fog/akamai/storage_test.rb +++ b/test/fog/akamai/storage_test.rb @@ -1,10 +1,12 @@ +# frozen_string_literal: true + require 'test_helper' module Fog module Akamai class StorageTest < Minitest::Test def setup - @storage = Fog::Storage::Akamai.new( + @storage = Fog::Akamai::Storage.new( akamai_host: 'example-nsu.akamai.net', akamai_key_name: 'key_name', akamai_key: 'key', @@ -13,7 +15,7 @@ def setup end def test_that_if_all_require_params_it_will_init - assert_instance_of Fog::Storage::Akamai::Real, @storage + assert_instance_of Fog::Akamai::Storage::Real, @storage end def test_format_path_will_prefix_with_the_cp_code diff --git a/test/fog/akamai/storage_test_base.rb b/test/fog/akamai/storage_test_base.rb index 36d0648..542537e 100644 --- a/test/fog/akamai/storage_test_base.rb +++ b/test/fog/akamai/storage_test_base.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'test_helper' module Fog diff --git a/test/fog/akamai_test.rb b/test/fog/akamai_test.rb index 6e9013f..ad1f005 100644 --- a/test/fog/akamai_test.rb +++ b/test/fog/akamai_test.rb @@ -1,4 +1,9 @@ +# frozen_string_literal: true + require 'test_helper' +require 'open3' +require 'rbconfig' +require 'stringio' module Fog class AkamaiTest < Minitest::Test @@ -9,5 +14,48 @@ def test_that_it_has_a_version_number def test_that_it_loads_the_storage_module refute_nil Fog::Storage[:akamai] end + + def test_the_real_service_lives_in_the_provider_namespace + assert_instance_of Fog::Akamai::Storage::Real, Fog::Storage[:akamai] + end + + def test_the_mock_service_lives_in_the_provider_namespace + Fog.mock! + assert_instance_of Fog::Akamai::Storage::Mock, Fog::Storage[:akamai] + ensure + Fog.unmock! + end + + def test_creating_the_service_does_not_log_a_deprecation + log = StringIO.new + original = Fog::Logger[:deprecation] + Fog::Logger[:deprecation] = log + + Fog::Storage.new(provider: :akamai) + + assert_empty log.string + ensure + Fog::Logger[:deprecation] = original + end + + def test_loading_the_provider_does_not_log_a_deprecation + script = "require 'fog/akamai'; Fog::Storage.new(provider: :akamai, akamai_host: 'h', akamai_key_name: 'k', akamai_key: 's', akamai_cp_code: '1')" + lib = File.expand_path('../../lib', __dir__) + _out, err, status = Open3.capture3(RbConfig.ruby, "-I#{lib}", '-e', script) + + assert status.success?, err + refute_match(/DEPRECATION/, err) + end + + def test_the_pre_0_6_constant_still_resolves_to_the_same_class_and_is_deprecated + deprecated = Warning[:deprecated] + Warning[:deprecated] = true + + klass = nil + assert_output(nil, /Fog::Storage::Akamai is deprecated/) { klass = Fog::Storage::Akamai } + assert_same Fog::Akamai::Storage, klass + ensure + Warning[:deprecated] = deprecated + end end end diff --git a/test/helpers/delete_request_stub.rb b/test/helpers/delete_request_stub.rb index c3d45a6..1c70dcb 100644 --- a/test/helpers/delete_request_stub.rb +++ b/test/helpers/delete_request_stub.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DeleteRequestStub def stub_delete(path) stub_request(:put, "https://example-nsu.akamai.net#{path}") diff --git a/test/helpers/dir_request_stub.rb b/test/helpers/dir_request_stub.rb index a3eda31..15c4ddf 100644 --- a/test/helpers/dir_request_stub.rb +++ b/test/helpers/dir_request_stub.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DirRequestStub def dir_body " diff --git a/test/helpers/download_request_stub.rb b/test/helpers/download_request_stub.rb index 84af4c1..fb836dc 100644 --- a/test/helpers/download_request_stub.rb +++ b/test/helpers/download_request_stub.rb @@ -1,6 +1,8 @@ +# frozen_string_literal: true + module DownloadRequestStub def download_body - File.read(File.expand_path('../../assets/test2.jpg', __FILE__)) + File.read(File.expand_path('../assets/test2.jpg', __dir__)) end def stub_download(path, status = 200) diff --git a/test/helpers/du_request_stub.rb b/test/helpers/du_request_stub.rb index 94dc4ba..98349da 100644 --- a/test/helpers/du_request_stub.rb +++ b/test/helpers/du_request_stub.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module DuRequestStub def du_body(path, files, bytes) " diff --git a/test/helpers/mkdir_request_stub.rb b/test/helpers/mkdir_request_stub.rb index 69ae1a8..eeff798 100644 --- a/test/helpers/mkdir_request_stub.rb +++ b/test/helpers/mkdir_request_stub.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module MkdirRequestStub def stub_mkdir(path) stub_request(:put, "https://example-nsu.akamai.net#{path}") diff --git a/test/helpers/mtime_request_stub.rb b/test/helpers/mtime_request_stub.rb index 436774d..f329fd4 100644 --- a/test/helpers/mtime_request_stub.rb +++ b/test/helpers/mtime_request_stub.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module MtimeRequestStub def stub_mtime(path) stub_request(:post, "https://example-nsu.akamai.net#{path}") diff --git a/test/helpers/rename_request_stub.rb b/test/helpers/rename_request_stub.rb index 6094eab..e632978 100644 --- a/test/helpers/rename_request_stub.rb +++ b/test/helpers/rename_request_stub.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module RenameRequestStub def stub_rename(source, _destination) stub_request(:post, "https://example-nsu.akamai.net#{source}") diff --git a/test/helpers/rmdir_request_stub.rb b/test/helpers/rmdir_request_stub.rb index 22827cc..e7872e0 100644 --- a/test/helpers/rmdir_request_stub.rb +++ b/test/helpers/rmdir_request_stub.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module RmdirRequestStub def stub_rmdir(path) stub_request(:post, "https://example-nsu.akamai.net#{path}") diff --git a/test/helpers/stat_request_stub.rb b/test/helpers/stat_request_stub.rb index 5377184..0fac218 100644 --- a/test/helpers/stat_request_stub.rb +++ b/test/helpers/stat_request_stub.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module StatRequestStub def stat_body_dir " diff --git a/test/helpers/symlink_request_stub.rb b/test/helpers/symlink_request_stub.rb index d2e3fa4..7f6bc14 100644 --- a/test/helpers/symlink_request_stub.rb +++ b/test/helpers/symlink_request_stub.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module SymlinkRequestStub def stub_symlink(source, _target) stub_request(:post, "https://example-nsu.akamai.net#{source}") diff --git a/test/helpers/upload_request_stub.rb b/test/helpers/upload_request_stub.rb index 24c13d7..c33f14b 100644 --- a/test/helpers/upload_request_stub.rb +++ b/test/helpers/upload_request_stub.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + module UploadRequestStub def stub_upload(path) stub_request(:put, "https://example-nsu.akamai.net#{path}") diff --git a/test/support/fog.rb b/test/support/fog.rb index 369e49c..2bd485f 100644 --- a/test/support/fog.rb +++ b/test/support/fog.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + Excon.defaults.merge!(debug_request: true, debug_response: true) Fog.credentials = { diff --git a/test/support/reporters.rb b/test/support/reporters.rb index 3282ef2..243fc0a 100644 --- a/test/support/reporters.rb +++ b/test/support/reporters.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'minitest/reporters' -MiniTest::Reporters.use! +Minitest::Reporters.use! diff --git a/test/support/webmock.rb b/test/support/webmock.rb index bc5f7bd..7990f26 100644 --- a/test/support/webmock.rb +++ b/test/support/webmock.rb @@ -1 +1,3 @@ +# frozen_string_literal: true + require 'webmock/minitest' diff --git a/test/test_helper.rb b/test/test_helper.rb index f91725b..d34f064 100644 --- a/test/test_helper.rb +++ b/test/test_helper.rb @@ -1,8 +1,15 @@ -$LOAD_PATH.unshift File.expand_path('../../lib', __FILE__) +# frozen_string_literal: true + +require 'simplecov' + +SimpleCov.start do + skip '/test/' +end + +$LOAD_PATH.unshift File.expand_path('../lib', __dir__) require 'minitest/autorun' +require 'minitest/mock' require 'fog/akamai' -require "codeclimate-test-reporter" -CodeClimate::TestReporter.start -Dir[File.expand_path('../support/**/*.rb', __FILE__)].each { |rb| require(rb) } +Dir[File.expand_path('support/**/*.rb', __dir__)].each { |rb| require(rb) }