Code Monkey home page Code Monkey logo

chemtrails's Introduction

Chemtrails

Build Status Code Climate Test Coverage

This gem allows you to fetch the configuration for your rails app from a Spring Cloud Config server.

Installation

Add this line to your application's Gemfile:

gem 'chemtrails'

And then execute:

$ bundle

Or install it yourself as:

$ gem install chemtrails

Configuration

To use your own config server, set the location and of your config server and any necessary credentials in the environment:

CONFIG_SERVER_URL=http://localhost:8080
CONFIG_SERVER_USERNAME=username
CONFIG_SERVER_PASSWORD=password

To use a Config Server service on PWS, set:

USE_P_CONFIG_SERVER_SERVICE=true

The rest of the configuration is the same regardless of what type of server you are using.

If you want to request values that are not on the master branch, you can optionally supply the branch name:

CONFIG_SERVER_BRANCH=production

If this is not provided, Spring Cloud Config will return values from the master branch.

You will also need to set your Rails environment so that Chemtrails knows which profile to fetch properties for.

RAILS_ENV={env}

If you'd like to fetch properties from a different profile (or multiple profiles) use CONFIG_SERVER_PROFILE_ACTIVE to override. e.g.

CONFIG_SERVER_PROFILE_ACTIVE=staging,web,noclip,muted

When your Rails app boots, it will fetch the configuration for the given environment from the config server and populate the ENV with the values it finds. It will use the application name and environment name to determine which set of values to fetch. For example, if the application is named Sandwich and is running in the production environment, it will fetch the configuration from the endpoint $CONFIG_SERVER_URL/sandwich/production. With Spring Cloud Config, this corresponds to a property source named sandwich-production.properties.

Disabling

If you do not provide a CONFIG_SERVER_URL then Chemtrails will not try to fetch variables from a config server.

Releasing a new version

Increase the version number in lib/chemtrails/version.rb

gem build chemtrails.gemspec
gem push chemtrails-$VERSION.gem

Credentials are in lastpass

License

The gem is available as open source under the terms of the MIT License.

chemtrails's People

Contributors

cobyrne-pivot avatar erd avatar kayline avatar tophat8855 avatar wschaefer-cfa avatar xtreme-peter-iskandar avatar zacpivotal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chemtrails's Issues

rails 5.x support

Looks like the support of Rails 5.0 was reverted to 4.0, any reasons?

When can it be available for 5.x support?

Reload configurations by connecting to the Spring Cloud Bus

Hi,

first thanks for this gem, as it had helped us to integrate our rails app into spring cloud config. The thing is that we need to reload ENV vars from SCC while the app is still running.

We are trying to modify the chemtrails railtie to mimic the Spring Cloud Bus (that uses RabbitMQ) to get events of "Configuration changed" with the next snippet

config.before_configuration do
      startup(Rails.application.class.parent.to_s.downcase, Rails.env, ENV) unless Rails.env.test?

      rabbit_host = ENV['rabbit_host']
      rabbit_port = ENV['rabbit_port'] ||
      rabbit_username = ENV['rabbit_username']
      rabbit_password = ENV['rabbit_password']
      rabbit_vhost = ENV['rabbit_vhost'] || '#'

      unless Rails.env.test? || rabbit_host.nil?
        conn = Bunny.new(
          :host => rabbit_host,
          :port => rabbit_port,
          :user => rabbit_username,
          :password => rabbit_password
        )
        conn.start

        ch = conn.create_channel
        q = ch.queue("springCloudBus.anonymous." + Rails.application.class.parent.to_s.downcase + Time.now.to_i.to_s, :auto_delete => true, :exclusive => true)
        q.bind("springCloudBus", :routing_key => "#")

        q.subscribe do |delivery_info, metadata, payload|
          obj = JSON.parse(payload)
          # Only reload the application on events of refresh configurattion
          if obj['type'] == "RefreshRemoteApplicationEvent"
            startup(Rails.application.class.parent.to_s.downcase, Rails.env, ENV)

            puts ENV
          end
        end
      end
    end

And it fetches an populates the ENV with the new configuration but for any reason when we visit any of the http endpoints to check the environment

# frozen_string_literal: true

class EnvController < ApplicationController

  before_action :authenticate_user!

  def index
    render json: ENV
  end

end

The value is the initial value when the application started.

Do you have any hint about what can we do to get this working? Is it possible?

Basic auth fails to work when using long username/pw combinations

When providing chemtrails with an extra long (read: actually secure) username and password, the gem will fail trying to receive information from the config server.

It gives some cryptic Syntax error: Unterminated quote string error. Upon further investigation, we discovered that it is most likely the gem Excon being used by chemtrails for http interaction with the config server. Using Excon manually with the credentials gets back a 400 Bad Request. Using a username and password with fewer characters fixes this issue.

I didn't check what the length Excon is actually okay with, I just chopped off some characters until it worked. ¯_(ツ)_/¯

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.