Skip to content
Snippets Groups Projects
Select Git revision
  • cd38c8eca90c83eeb100f9138cb8726e1f217e6c
  • master default protected
2 results

common

  • Clone with SSH
  • Clone with HTTPS
  • user avatar
    Tank Tang authored and Vincent Jiang (LEI) committed
    cd38c8ec
    History

    Microsoft Azure Storage Common Client Library for Ruby

    Gem Version

    • Master: Master Build Status Coverage Status
    • Dev: Dev Build Status Coverage Status

    This project provides a Ruby package that supports service client libraries.

    Supported Ruby Versions

    • Ruby 1.9.3 to 2.5

    Note:

    • x64 Ruby for Windows is known to have some compatibility issues.
    • azure-storage-common depends on gem nokogiri. For Ruby version lower than 2.2, please install the compatible nokogiri before trying to install azure-storage.

    Getting Started

    Install the rubygem package

    You can install the azure storage common rubygem package directly.

    gem install azure-storage-common

    Create client

    You can use this module to create client that can be later shared by service modules, to avoid repeating code of creating storage client.

    There are two ways you can create the client:

    1. via code
    2. via environment variables

    Via Code

    • Against Microsoft Azure Services in the cloud
    
      require 'azure/storage/common'
    
      # Setup a specific instance of an Azure::Storage::Common::Client
      client = Azure::Storage::Common::Client.create(storage_account_name: <your account name>, storage_access_key: <your access key>)
    
      # Configure a ca_cert.pem file if you are having issues with ssl peer verification
      client.ca_file = './ca_file.pem'
    
    • Against local Emulator (Windows Only)
    
      require 'azure/storage/common'
      client = Azure::Storage::Common::Client.create_development
    
      # Or create by options and provide your own proxy_uri
      client = Azure::Storage::Common::Client.create(use_development_storage: true, development_storage_proxy_uri: <your proxy uri>)
    

    Via Environment Variables

    • Against Microsoft Azure Storage Services in the cloud

      export AZURE_STORAGE_ACCOUNT = <your azure storage account name>
      export AZURE_STORAGE_ACCESS_KEY = <your azure storage access key>
    • Against local Emulator (Windows Only)

      export EMULATED = true
    • SSL Certificate File if having issues with ssl peer verification

      SSL_CERT_FILE=<path to *.pem>

    Usage

    Shared Access Signature generation

    
    require "azure/storage/common"
    
    # Creating an instance of `Azure::Storage::Common::Core::Auth::SharedAccessSignature`
    generator = Azure::Storage::Common::Core::Auth::SharedAccessSignature.new(your_account_name, your_access_key)
    
    # The generator now can be used to create service SAS or account SAS.
    generator.generate_service_sas_token(my_path_or_table_name, my_sas_options)
    generator.generate_account_sas_token(my_account_sas_options)
    # For details about the possible options, please reference the document of the class `Azure::Storage::Common::Core::Auth::SharedAccessSignature`
    

    Access Token

    Please refer to the below links for obtaining an access token:

    require "azure/storage/common"
    
    access_token = <your initial access token>
    
    # Creating an instance of `Azure::Storage::Common::Core::TokenCredential`
    token_credential = Azure::Storage::Common::Core::TokenCredential.new access_token
    token_signer = Azure::Storage::Common::Core::Auth::TokenSigner.new token_credential
    common_token_client = Azure::Storage::Common::Client.create.new(storage_account_name: <your_account_name>, signer: token_signer)
    
    # Refresh internal is 50 minutes
    refresh_interval = 50 * 60
    # The user-defined thread that renews the access token
    cancelled = false
    renew_token = Thread.new do
      Thread.stop
      while !cancelled
        sleep(refresh_interval)
    
        # Renew the access token here
    
        # Update the access token to the credential
        token_credential.renew_token <new_access_token>
      end
    end
    sleep 0.1 while renew_token.status != 'sleep'
    renew_token.run
    
    # Call client functions as usaual
    

    Code of Conduct

    This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.