├── conf └── .gitkeep ├── env └── .gitkeep ├── template └── .gitkeep ├── versions └── 1.0.0 │ └── .gitkeep ├── bin ├── teardown ├── setup ├── install ├── control └── status.rb ├── metadata ├── managed_files.yml └── manifest.yml ├── LICENSE ├── README.md └── ironmq-openshift-cartridge.spec /conf/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /env/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /template/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /versions/1.0.0/.gitkeep: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /bin/teardown: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | source $OPENSHIFT_CARTRIDGE_SDK_BASH 4 | 5 | # uninstall gem if needed 6 | -------------------------------------------------------------------------------- /metadata/managed_files.yml: -------------------------------------------------------------------------------- 1 | --- 2 | locked_files: 3 | - ironmq/ 4 | - ironmq/metadata/ 5 | - ironmq/env/ 6 | - ironmq/conf/ 7 | -------------------------------------------------------------------------------- /bin/setup: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | source $OPENSHIFT_CARTRIDGE_SDK_BASH 4 | 5 | case "$1" in 6 | -v|--version) 7 | version="$2" 8 | esac 9 | 10 | echo "$version" > "$OPENSHIFT_IRONMQ_DIR/env/OPENSHIFT_IRONMQ_VERSION" 11 | -------------------------------------------------------------------------------- /bin/install: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | source $OPENSHIFT_CARTRIDGE_SDK_BASH 4 | 5 | # gem install iron_mq - uncommment 6 | # OR pre-install it and just fix GEM_PATH (in control script) 7 | 8 | client_result "" 9 | client_result "TODO: Main point of cartridge - tell user how to register and download iron.json" 10 | client_result "" 11 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 2 | -------------------------------------------------------------------------------- /bin/control: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | source $OPENSHIFT_CARTRIDGE_SDK_BASH 4 | 5 | function start() { 6 | #adjust GEM_PATH & co in pre-packaged lib way 7 | } 8 | 9 | function stop() { 10 | #adjust GEM_PATH & co back in pre-packaged lib way - might be not so trivial 11 | } 12 | 13 | function status() { 14 | dir=$(cd -P -- "$(dirname -- "$0")" && pwd -P) 15 | client_result $(ruby "$dir/status.rb") 16 | } 17 | 18 | case "$1" in 19 | start) start ;; 20 | stop) stop ;; 21 | status) status ;; 22 | tidy) tidy ;; 23 | *) exit 0 24 | esac 25 | -------------------------------------------------------------------------------- /metadata/manifest.yml: -------------------------------------------------------------------------------- 1 | Name: ironmq 2 | Cartridge-Short-Name: IRONMQ 3 | Version: 1.0.0 4 | Architecture: noarch 5 | Display-Name: IronMQ 1.0.0 6 | Description: "The IronMQ cartridge allows you to interact with Iron.io's MQ." 7 | License: "ASL 2.0" 8 | License-Url: http://www.apache.org/licenses/LICENSE-2.0.txt 9 | Website: "http://iron.io" 10 | Cartridge-Version: 1.0.0 11 | Cartridge-Vendor: iron.io 12 | Categories: 13 | - embedded 14 | Help-Topics: 15 | "Getting Started Guide": https://iron.io/FIXME 16 | Provides: 17 | - ironmq 18 | Scaling: 19 | Min: 1 20 | Max: 1 21 | Install-Build-Required: true 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | We need to decide how we want our libs to be packaged/installed. 2 | 3 | 1. Just run `gem install iron_mq` (and similar for other langs) in install/setup script (and uninstall in teardown, though it'll leave deps installed). Easiest way, but virtually no controll on what's going on. 4 | 2. Package libs with cartridge (in data dir or similar) modify GEM_PATH (and similar for other langs) in start hook. Will force us to update cartridge on every affected lib update. Not good. 5 | 3. Make gems (and pips etc) packaged as RPM, add them as deps to cartridge as all other cartridges do. Easiest for us way, granular updates. 6 | 7 | Provision. On setup time we can ask user for iron.io project_id/token and if he is new - ask for email (can't find it in env) and create new account. Problem is - we'll need to depend on ruby cartridge to do that (or spend some time doing provisioning using shell/curl). 8 | -------------------------------------------------------------------------------- /ironmq-openshift-cartridge.spec: -------------------------------------------------------------------------------- 1 | %global cartridgedir %{_libexecdir}/openshift/cartridges/v2/ironmq 2 | %global frameworkdir %{_libexecdir}/openshift/cartridges/v2/ironmq 3 | 4 | Name: ironmq-openshift-cartridge 5 | Version: 1.0.0 6 | Release: 1%{?dist} 7 | Summary: Embedded IronMQ support for OpenShift 8 | Group: Development/Languages 9 | License: ASL 2.0 10 | URL: https://iron.io 11 | Source0: http://TODO.com/FIXME 12 | Requires: rubygem(openshift-origin-node) 13 | Requires: openshift-origin-node-util 14 | 15 | BuildArch: noarch 16 | BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root 17 | BuildArch: noarch 18 | 19 | %description 20 | IronMQ cartridge for openshift. (Cartridge Format V2) 21 | 22 | 23 | %prep 24 | %setup -q 25 | 26 | %build 27 | 28 | %install 29 | rm -rf %{buildroot} 30 | mkdir -p %{buildroot}%{cartridgedir} 31 | mkdir -p %{buildroot}/%{_sysconfdir}/openshift/cartridges/v2 32 | cp -r * %{buildroot}%{cartridgedir}/ 33 | ln -s %{cartridgedir}/conf/ %{buildroot}/%{_sysconfdir}/openshift/cartridges/v2/%{name} 34 | 35 | %clean 36 | rm -rf %{buildroot} 37 | 38 | %post 39 | %{_sbindir}/oo-admin-cartridge --action install --offline --source /usr/libexec/openshift/cartridges/v2/ironmq 40 | 41 | %files 42 | %defattr(-,root,root,-) 43 | %dir %{cartridgedir} 44 | %dir %{cartridgedir}/bin 45 | %dir %{cartridgedir}/env 46 | %dir %{cartridgedir}/metadata 47 | %dir %{cartridgedir}/versions 48 | %attr(0755,-,-) %{cartridgedir}/bin/ 49 | %attr(0755,-,-) %{frameworkdir} 50 | %{_sysconfdir}/openshift/cartridges/v2/%{name} 51 | %{cartridgedir}/metadata/manifest.yml 52 | %doc %{cartridgedir}/README.md 53 | %doc %{cartridgedir}/LICENSE 54 | 55 | 56 | %changelog 57 | -------------------------------------------------------------------------------- /bin/status.rb: -------------------------------------------------------------------------------- 1 | require 'json' 2 | require 'yaml' 3 | require 'uri' 4 | require 'net/http' 5 | require 'net/https' 6 | 7 | module IronMQ 8 | class CoreClient 9 | attr_accessor :content_type 10 | attr_accessor :env 11 | 12 | def initialize(company, product, options = {}, default_options = {}, extra_options_list = []) 13 | @options_list = [:scheme, :host, :port, :user_agent] + extra_options_list 14 | 15 | metaclass = class << self 16 | self 17 | end 18 | 19 | @options_list.each do |option| 20 | metaclass.send(:define_method, option.to_s) do 21 | instance_variable_get('@' + option.to_s) 22 | end 23 | 24 | metaclass.send(:define_method, option.to_s + '=') do |value| 25 | instance_variable_set('@' + option.to_s, value) 26 | end 27 | end 28 | 29 | @env = options[:env] || options['env'] 30 | @env ||= ENV[company.upcase + '_' + product.upcase + '_ENV'] || ENV[company.upcase + '_ENV'] 31 | 32 | load_from_hash('params', options) 33 | 34 | load_from_config(company, product, options[:config] || options['config']) 35 | 36 | load_from_config(company, product, ENV[company.upcase + '_' + product.upcase + '_CONFIG']) 37 | load_from_config(company, product, ENV[company.upcase + '_CONFIG']) 38 | 39 | load_from_env(company.upcase + '_' + product.upcase) 40 | load_from_env(company.upcase) 41 | 42 | suffixes = [] 43 | 44 | unless @env.nil? 45 | suffixes << "-#{@env}" 46 | suffixes << "_#{@env}" 47 | end 48 | 49 | suffixes << '' 50 | 51 | suffixes.each do |suffix| 52 | ['.json', '.yml'].each do |ext| 53 | ["#{company}-#{product}", "#{company}_#{product}", company].each do |config_base| 54 | load_from_config(company, product, "#{Dir.pwd}/#{config_base}#{suffix}#{ext}") 55 | load_from_config(company, product, "#{Dir.pwd}/.#{config_base}#{suffix}#{ext}") 56 | load_from_config(company, product, "#{Dir.pwd}/config/#{config_base}#{suffix}#{ext}") 57 | load_from_config(company, product, "#{Dir.pwd}/config/.#{config_base}#{suffix}#{ext}") 58 | load_from_config(company, product, "~/#{config_base}#{suffix}#{ext}") 59 | load_from_config(company, product, "~/.#{config_base}#{suffix}#{ext}") 60 | end 61 | end 62 | end 63 | 64 | load_from_hash('defaults', default_options) 65 | load_from_hash('defaults', {:user_agent => 'ironmq-openshift-cartridge'}) 66 | 67 | @content_type = 'application/json' 68 | end 69 | 70 | def set_option(source, name, value) 71 | if send(name.to_s).nil? && (not value.nil?) 72 | send(name.to_s + '=', value) 73 | end 74 | end 75 | 76 | def load_from_hash(source, hash) 77 | return if hash.nil? 78 | 79 | @options_list.each do |o| 80 | set_option(source, o, hash[o.to_sym] || hash[o.to_s]) 81 | end 82 | end 83 | 84 | def load_from_env(prefix) 85 | @options_list.each do |o| 86 | set_option('environment variable', o, ENV[prefix + '_' + o.to_s.upcase]) 87 | end 88 | end 89 | 90 | def get_sub_hash(hash, subs) 91 | return nil if hash.nil? 92 | 93 | subs.each do |sub| 94 | return nil if hash[sub].nil? 95 | 96 | hash = hash[sub] 97 | end 98 | 99 | hash 100 | end 101 | 102 | def load_from_config(company, product, config_file) 103 | return if config_file.nil? 104 | 105 | if File.exists?(File.expand_path(config_file)) 106 | config_data = '{}' 107 | 108 | begin 109 | config_data = File.read(File.expand_path(config_file)) 110 | rescue 111 | return 112 | end 113 | 114 | config = nil 115 | 116 | if config_file.end_with?('.yml') 117 | config = YAML.load(config_data) 118 | else 119 | config = JSON.parse(config_data) 120 | end 121 | 122 | unless @env.nil? 123 | load_from_hash(config_file, get_sub_hash(config, [@env, "#{company}_#{product}"])) 124 | load_from_hash(config_file, get_sub_hash(config, [@env, company, product])) 125 | load_from_hash(config_file, get_sub_hash(config, [@env, product])) 126 | load_from_hash(config_file, get_sub_hash(config, [@env, company])) 127 | 128 | load_from_hash(config_file, get_sub_hash(config, ["#{company}_#{product}", @env])) 129 | load_from_hash(config_file, get_sub_hash(config, [company, product, @env])) 130 | load_from_hash(config_file, get_sub_hash(config, [product, @env])) 131 | load_from_hash(config_file, get_sub_hash(config, [company, @env])) 132 | 133 | load_from_hash(config_file, get_sub_hash(config, [@env])) 134 | end 135 | 136 | load_from_hash(config_file, get_sub_hash(config, ["#{company}_#{product}"])) 137 | load_from_hash(config_file, get_sub_hash(config, [company, product])) 138 | load_from_hash(config_file, get_sub_hash(config, [product])) 139 | load_from_hash(config_file, get_sub_hash(config, [company])) 140 | load_from_hash(config_file, get_sub_hash(config, [])) 141 | end 142 | end 143 | 144 | def options(return_strings = false) 145 | res = {} 146 | 147 | @options_list.each do |option| 148 | res[return_strings ? option.to_s : option.to_sym] = send(option.to_s) 149 | end 150 | 151 | res 152 | end 153 | 154 | def headers 155 | {'User-Agent' => @user_agent} 156 | end 157 | 158 | def base_url 159 | "#{scheme}://#{host}:#{port}/" 160 | end 161 | 162 | def url(method) 163 | base_url + method 164 | end 165 | 166 | def get(method, params = {}) 167 | uri = URI.parse(url(method)) 168 | uri.query = URI.encode_www_form(params) 169 | 170 | req = Net::HTTP::Get.new(uri) 171 | 172 | headers.each do |name, value| 173 | req[name] = value 174 | end 175 | 176 | http = Net::HTTP.new(uri.hostname, uri.port) 177 | 178 | if scheme == 'https' 179 | http.use_ssl = true 180 | http.verify_mode = OpenSSL::SSL::VERIFY_NONE 181 | end 182 | 183 | http.request(req) 184 | end 185 | 186 | def parse_response(response, parse_json = true) 187 | return nil if (response.code.to_i < 200 || response.code.to_i >= 300) 188 | 189 | body = String.new(response.body) 190 | 191 | return body unless parse_json 192 | 193 | JSON.parse(body) 194 | end 195 | end 196 | 197 | class Client < CoreClient 198 | AWS_US_EAST_HOST = 'mq-aws-us-east-1.iron.io' 199 | 200 | def initialize(options={}) 201 | default_options = { 202 | :scheme => 'https', 203 | :host => IronMQ::Client::AWS_US_EAST_HOST, 204 | :port => 443, 205 | :api_version => 1 206 | } 207 | 208 | super('iron', 'mq', options, default_options, [:project_id, :token, :api_version]) 209 | end 210 | 211 | def headers 212 | super.merge({'Authorization' => "OAuth #{@token}"}) 213 | end 214 | 215 | def base_url 216 | @base_url = "#{super}#{@api_version}/projects/#{@project_id}/queues" 217 | end 218 | 219 | def queues(options = {}) 220 | response = nil 221 | 222 | #begin 223 | response = parse_response(get('', options)) 224 | #rescue 225 | #end 226 | 227 | response 228 | end 229 | end 230 | end 231 | 232 | client = IronMQ::Client.new 233 | 234 | puts client.queues.inspect # FIXME - show formatted info 235 | --------------------------------------------------------------------------------