Module: BucketClient

Defined in:
lib/bucket_client.rb,
lib/bucket_client/bucket.rb,
lib/bucket_client/client.rb,
lib/bucket_client/version.rb,
lib/bucket_client/aws/aws_bucket.rb,
lib/bucket_client/aws/aws_client.rb,
lib/bucket_client/gcp/gcp_bucket.rb,
lib/bucket_client/gcp/gcp_client.rb,
lib/bucket_client/dev/local_bucket.rb,
lib/bucket_client/dev/local_client.rb,
lib/bucket_client/azure/azure_bucket.rb,
lib/bucket_client/azure/azure_client.rb,
lib/bucket_client/aws/aws_http_client.rb,
lib/bucket_client/aws4_request_signer.rb,
lib/bucket_client/digital_ocean/digital_ocean_bucket.rb,
lib/bucket_client/digital_ocean/digital_ocean_client.rb,
lib/bucket_client/digital_ocean/digital_ocean_http_client.rb

Defined Under Namespace

Modules: BlobMethods, BucketMethods, KeyMethod, UriMethod Classes: AWS4RequestSigner, AWSBucket, AWSClient, AWSHttpClient, AzureBucket, AzureClient, Bucket, Client, DigitalOceanBucket, DigitalOceanClient, DigitalOceanHttpClient, GCPBucket, GCPClient, LocalBucket, LocalClient

Constant Summary collapse

VERSION =
"0.1.4"

Class Method Summary collapse

Class Method Details

.generate(type: :local, id: nil, secret: nil, region: nil, path: nil, principal: nil) ⇒ BucketClient::Client

:local for local, :aws for AWS S3 Bucket :azure for Azure Blob Storage :spaces for DigitalOcean Spaces :gcp for Google Cloud Platform Storage Account For GCP, this is your project id For AWS, this is your access ID For Digital Ocean spaces, this is your access ID For Azure, this is your account name for your blob storage account For GCP, this can either be a path to your secret.json, or it can be the JSON serialized as a hash. For AWS, this is your secret key For Digital Ocean spaces, this is your secret key For Azure, this is your secret key For AWS, this is your region string. eg: ap-southeast-1 For Digital Ocean Spaces, this is your region string. ep: sgp1

Parameters:

  • type (Symbol) (defaults to: :local)

    the type of client to generate. Accepts

  • id (String) (defaults to: nil)

    The id for the client. Only applicable to :aws, :azure, :spaces and :gcp

  • secret (String or Hash) (defaults to: nil)

    The secret for the client. Only applicable to :aws, :azure, :spaces and :gcp

  • region (String) (defaults to: nil)

    The region of your bucket. Only applicable to :aws and :spaces

  • path (String) (defaults to: nil)

    The local path for mocking a bucket (using disk). Only applicable to :local

  • principal (String) (defaults to: nil)

    The public path of the bucket. Will use value of “path” if not provided. Only applicable to :local

Returns:



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/bucket_client.rb', line 37

def BucketClient.generate(type: :local, id: nil, secret: nil, region: nil, path: nil, principal: nil)
  http = KirinHttp::BasicClient.new
  case type
    when :local
      raise ArgumentError.new("Path not provided") if path.nil?
      LocalClient.new(path, principal)
    when :aws
      raise ArgumentError.new("id not provided") if id.nil?
      raise ArgumentError.new("secreted not provided") if secret.nil?
      raise ArgumentError.new("region not provided") if region.nil?
      AWSClient.new(http, id, secret, region)
    when :azure
      raise ArgumentError.new("account name/id not provided") if id.nil?
      raise ArgumentError.new("secret not provided") if secret.nil?
      AzureClient.new(id, secret)
    when :spaces
      raise ArgumentError.new("id not provided") if id.nil?
      raise ArgumentError.new("secreted not provided") if secret.nil?
      raise ArgumentError.new("region not provided") if region.nil?
      DigitalOceanClient.new(http, id, secret, region)
    when :gcp
      raise ArgumentError.new("project id not provided") if id.nil?
      raise ArgumentError.new("secret not provided") if secret.nil?
      GCPClient.new(id, secret)
    else
      raise ArgumentError.new("Unknown Client type: " + type.to_s)
  end
end