ocp_registry 0.0.1.alpha
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +25 -0
- data/Gemfile +17 -0
- data/Gemfile.lock +65 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/bin/ocp_registry +28 -0
- data/config/example-mysql.yml +40 -0
- data/config/example-sqlite.yml +33 -0
- data/lib/ocp_registry.rb +29 -0
- data/lib/ocp_registry/api_controller.rb +146 -0
- data/lib/ocp_registry/application_manager.rb +213 -0
- data/lib/ocp_registry/cloud_manager/mock.rb +5 -0
- data/lib/ocp_registry/cloud_manager/mock/mock.rb +191 -0
- data/lib/ocp_registry/cloud_manager/mock/model.rb +22 -0
- data/lib/ocp_registry/cloud_manager/openstack.rb +4 -0
- data/lib/ocp_registry/cloud_manager/openstack/cinder_helper.rb +27 -0
- data/lib/ocp_registry/cloud_manager/openstack/keystone_helper.rb +57 -0
- data/lib/ocp_registry/cloud_manager/openstack/nova_helper.rb +37 -0
- data/lib/ocp_registry/cloud_manager/openstack/openstack.rb +126 -0
- data/lib/ocp_registry/common.rb +54 -0
- data/lib/ocp_registry/config.rb +96 -0
- data/lib/ocp_registry/db/001_db_initialize.rb +16 -0
- data/lib/ocp_registry/error.rb +16 -0
- data/lib/ocp_registry/mail_client.rb +141 -0
- data/lib/ocp_registry/models.rb +7 -0
- data/lib/ocp_registry/models/registry_application.rb +10 -0
- data/lib/ocp_registry/runner.rb +47 -0
- data/lib/ocp_registry/version.rb +3 -0
- data/lib/ocp_registry/yaml_helper.rb +23 -0
- data/mail_template/approve_admin.erb +14 -0
- data/mail_template/approve_user.erb +22 -0
- data/mail_template/refuse_admin.erb +16 -0
- data/mail_template/refuse_user.erb +17 -0
- data/mail_template/request_admin.erb +15 -0
- data/mail_template/request_user.erb +16 -0
- data/ocp_registry.gemspec +34 -0
- data/public/bootstrap/css/bootstrap-responsive.css +1109 -0
- data/public/bootstrap/css/bootstrap-responsive.min.css +9 -0
- data/public/bootstrap/css/bootstrap.css +6167 -0
- data/public/bootstrap/css/bootstrap.min.css +9 -0
- data/public/bootstrap/img/glyphicons-halflings-white.png +0 -0
- data/public/bootstrap/img/glyphicons-halflings.png +0 -0
- data/public/bootstrap/js/bootstrap.js +2280 -0
- data/public/bootstrap/js/bootstrap.min.js +6 -0
- data/public/common.css +104 -0
- data/public/favicon.ico +0 -0
- data/public/images/loading.gif +0 -0
- data/public/jquery-1.10.2.min.js +6 -0
- data/public/jquery-1.10.2.min.map +1 -0
- data/public/jquery.json-2.4.min.js +23 -0
- data/public/noty/.gitignore +8 -0
- data/public/noty/LICENSE.txt +20 -0
- data/public/noty/README.markdown +22 -0
- data/public/noty/demo/allLayouts.html +91 -0
- data/public/noty/demo/allTypes.html +86 -0
- data/public/noty/demo/api.html +103 -0
- data/public/noty/demo/buttons.css +320 -0
- data/public/noty/demo/consumingAlert.html +78 -0
- data/public/noty/demo/customContainer.html +90 -0
- data/public/noty/demo/index.html +66 -0
- data/public/noty/demo/jquery-1.7.2.min.js +4 -0
- data/public/noty/demo/usingMaxVisible.html +104 -0
- data/public/noty/demo/usingWithButtons.html +104 -0
- data/public/noty/demo/usingWithButtons2.html +98 -0
- data/public/noty/demo/usingWithModal.html +87 -0
- data/public/noty/demo/usingWithOldOptions.html +110 -0
- data/public/noty/js/jquery.noty.js +547 -0
- data/public/noty/js/layouts/bottom.js +34 -0
- data/public/noty/js/layouts/bottomCenter.js +41 -0
- data/public/noty/js/layouts/bottomLeft.js +43 -0
- data/public/noty/js/layouts/bottomRight.js +43 -0
- data/public/noty/js/layouts/center.js +56 -0
- data/public/noty/js/layouts/centerLeft.js +61 -0
- data/public/noty/js/layouts/centerRight.js +61 -0
- data/public/noty/js/layouts/inline.js +31 -0
- data/public/noty/js/layouts/top.js +34 -0
- data/public/noty/js/layouts/topCenter.js +41 -0
- data/public/noty/js/layouts/topLeft.js +43 -0
- data/public/noty/js/layouts/topRight.js +43 -0
- data/public/noty/js/promise.js +432 -0
- data/public/noty/js/themes/default.js +156 -0
- data/views/apply.erb +134 -0
- data/views/base.erb +25 -0
- data/views/list.erb +41 -0
- data/views/review.erb +141 -0
- data/views/show.erb +96 -0
- data/views/view.erb +7 -0
- metadata +294 -0
data/.gitignore
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
coverage
|
6
|
+
InstalledFiles
|
7
|
+
lib/bundler/man
|
8
|
+
pkg
|
9
|
+
rdoc
|
10
|
+
spec/reports
|
11
|
+
test/tmp
|
12
|
+
test/version_tmp
|
13
|
+
tmp
|
14
|
+
tmp/registry.log
|
15
|
+
|
16
|
+
# YARD artifacts
|
17
|
+
.yardoc
|
18
|
+
_yardoc
|
19
|
+
doc/
|
20
|
+
|
21
|
+
.tags
|
22
|
+
|
23
|
+
.tags_sorted_by_file
|
24
|
+
|
25
|
+
.DS_Store
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
GEM
|
2
|
+
remote: https://rubygems.org/
|
3
|
+
specs:
|
4
|
+
builder (3.2.2)
|
5
|
+
daemons (1.1.9)
|
6
|
+
diff-lcs (1.2.4)
|
7
|
+
eventmachine (1.0.3)
|
8
|
+
excon (0.23.0)
|
9
|
+
fog (1.12.1)
|
10
|
+
builder
|
11
|
+
excon (~> 0.23.0)
|
12
|
+
formatador (~> 0.2.0)
|
13
|
+
mime-types
|
14
|
+
multi_json (~> 1.0)
|
15
|
+
net-scp (~> 1.1)
|
16
|
+
net-ssh (>= 2.1.3)
|
17
|
+
nokogiri (~> 1.5.0)
|
18
|
+
ruby-hmac
|
19
|
+
formatador (0.2.4)
|
20
|
+
mime-types (1.23)
|
21
|
+
multi_json (1.7.7)
|
22
|
+
mysql2 (0.3.11)
|
23
|
+
net-scp (1.1.1)
|
24
|
+
net-ssh (>= 2.6.5)
|
25
|
+
net-ssh (2.6.7)
|
26
|
+
nokogiri (1.5.10)
|
27
|
+
rack (1.5.2)
|
28
|
+
rack-protection (1.5.0)
|
29
|
+
rack
|
30
|
+
rspec (2.13.0)
|
31
|
+
rspec-core (~> 2.13.0)
|
32
|
+
rspec-expectations (~> 2.13.0)
|
33
|
+
rspec-mocks (~> 2.13.0)
|
34
|
+
rspec-core (2.13.1)
|
35
|
+
rspec-expectations (2.13.0)
|
36
|
+
diff-lcs (>= 1.1.3, < 2.0)
|
37
|
+
rspec-mocks (2.13.1)
|
38
|
+
ruby-hmac (0.4.0)
|
39
|
+
sequel (4.0.0)
|
40
|
+
sinatra (1.4.3)
|
41
|
+
rack (~> 1.4)
|
42
|
+
rack-protection (~> 1.4)
|
43
|
+
tilt (~> 1.3, >= 1.3.4)
|
44
|
+
sqlite3 (1.3.7)
|
45
|
+
thin (1.5.1)
|
46
|
+
daemons (>= 1.0.9)
|
47
|
+
eventmachine (>= 0.12.6)
|
48
|
+
rack (>= 1.0.0)
|
49
|
+
tilt (1.4.1)
|
50
|
+
tlsmail (0.0.1)
|
51
|
+
yajl-ruby (1.1.0)
|
52
|
+
|
53
|
+
PLATFORMS
|
54
|
+
ruby
|
55
|
+
|
56
|
+
DEPENDENCIES
|
57
|
+
fog
|
58
|
+
mysql2
|
59
|
+
rspec
|
60
|
+
sequel
|
61
|
+
sinatra
|
62
|
+
sqlite3
|
63
|
+
thin
|
64
|
+
tlsmail
|
65
|
+
yajl-ruby
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Wei Tie
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# OcpRegistry
|
2
|
+
|
3
|
+
A simple openstack self-registration app
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'ocp_registry'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install ocp_registry
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
ocp_registry -c <your-config-file>
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/bin/ocp_registry
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative "../lib/ocp_registry"
|
4
|
+
require "optparse"
|
5
|
+
|
6
|
+
config_file = nil
|
7
|
+
|
8
|
+
opts = OptionParser.new do |opts|
|
9
|
+
opts.on("-c", "--config FILE", "configuration file") do |opt|
|
10
|
+
config_file = opt
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
opts.parse!(ARGV.dup)
|
15
|
+
|
16
|
+
if config_file.nil?
|
17
|
+
puts opts
|
18
|
+
exit 1
|
19
|
+
end
|
20
|
+
|
21
|
+
runner = Ocp::Registry::Runner.new(config_file)
|
22
|
+
|
23
|
+
Signal.trap("INT") do
|
24
|
+
runner.stop
|
25
|
+
exit(1)
|
26
|
+
end
|
27
|
+
|
28
|
+
runner.run
|
@@ -0,0 +1,40 @@
|
|
1
|
+
---
|
2
|
+
loglevel: debug
|
3
|
+
logfile: tmp/registry.log
|
4
|
+
|
5
|
+
http:
|
6
|
+
base_url: localhost
|
7
|
+
port: 6799
|
8
|
+
user: admin
|
9
|
+
password: admin
|
10
|
+
|
11
|
+
db:
|
12
|
+
adapter: mysql
|
13
|
+
user: registry
|
14
|
+
password: registry
|
15
|
+
host: 127.0.0.1
|
16
|
+
port: 3306
|
17
|
+
database: registry
|
18
|
+
connection_options:
|
19
|
+
max_connections: 32
|
20
|
+
pool_timeout: 10
|
21
|
+
|
22
|
+
cloud:
|
23
|
+
login_url: <dashboard login url>
|
24
|
+
plugin: openstack
|
25
|
+
default_role:
|
26
|
+
openstack:
|
27
|
+
auth_url: <%= auth_url %>
|
28
|
+
username: <%= username %>
|
29
|
+
api_key: <%= api_key %>
|
30
|
+
tenant: <%= tenant %>
|
31
|
+
|
32
|
+
mail:
|
33
|
+
admin_emails:
|
34
|
+
worker:
|
35
|
+
smtp_server:
|
36
|
+
port:
|
37
|
+
helo:
|
38
|
+
username:
|
39
|
+
password:
|
40
|
+
authentication:
|
@@ -0,0 +1,33 @@
|
|
1
|
+
---
|
2
|
+
loglevel: debug
|
3
|
+
logfile: tmp/registry.log
|
4
|
+
|
5
|
+
http:
|
6
|
+
base_url: localhost
|
7
|
+
port: 6799
|
8
|
+
user: admin
|
9
|
+
password: admin
|
10
|
+
|
11
|
+
db:
|
12
|
+
adapter: sqlite
|
13
|
+
database: tmp/registry.db
|
14
|
+
|
15
|
+
cloud:
|
16
|
+
login_url: <dashboard login url>
|
17
|
+
plugin: openstack
|
18
|
+
default_role:
|
19
|
+
openstack:
|
20
|
+
auth_url: <%= auth_url %>
|
21
|
+
username: <%= username %>
|
22
|
+
api_key: <%= api_key %>
|
23
|
+
tenant: <%= tenant %>
|
24
|
+
|
25
|
+
mail:
|
26
|
+
admin_emails:
|
27
|
+
worker:
|
28
|
+
smtp_server:
|
29
|
+
port:
|
30
|
+
helo:
|
31
|
+
username:
|
32
|
+
password:
|
33
|
+
authentication:
|
data/lib/ocp_registry.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
$:.unshift(File.join(File.dirname(__FILE__), 'lib'))
|
2
|
+
$:.unshift(File.dirname(__FILE__))
|
3
|
+
|
4
|
+
module Ocp
|
5
|
+
module Registry
|
6
|
+
autoload :Models, "ocp_registry/models"
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
require "fog"
|
11
|
+
require "logger"
|
12
|
+
require "sequel"
|
13
|
+
require "sinatra/base"
|
14
|
+
require "thin"
|
15
|
+
require "yajl"
|
16
|
+
require "securerandom"
|
17
|
+
require "uri"
|
18
|
+
require "erb"
|
19
|
+
|
20
|
+
require "ocp_registry/yaml_helper"
|
21
|
+
require "ocp_registry/runner"
|
22
|
+
require "ocp_registry/error"
|
23
|
+
require "ocp_registry/config"
|
24
|
+
require "ocp_registry/application_manager"
|
25
|
+
require "ocp_registry/api_controller"
|
26
|
+
require "ocp_registry/common"
|
27
|
+
|
28
|
+
|
29
|
+
Sequel::Model.plugin :validation_helpers
|
@@ -0,0 +1,146 @@
|
|
1
|
+
|
2
|
+
module Ocp::Registry
|
3
|
+
|
4
|
+
class ApiController < Sinatra::Base
|
5
|
+
|
6
|
+
set :root, File.join(File.dirname(__FILE__), '../../')
|
7
|
+
|
8
|
+
not_found do
|
9
|
+
exception = request.env["sinatra.error"]
|
10
|
+
@logger.debug(request.path_info)
|
11
|
+
@logger.error(exception.message)
|
12
|
+
do_response({:status => "not_found"}, nil)
|
13
|
+
end
|
14
|
+
|
15
|
+
error do
|
16
|
+
exception = request.env["sinatra.error"]
|
17
|
+
@logger.error(exception)
|
18
|
+
status(500)
|
19
|
+
do_response({:status => "error"}, nil)
|
20
|
+
end
|
21
|
+
|
22
|
+
error Ocp::Registry::Error do
|
23
|
+
error = request.env["sinatra.error"]
|
24
|
+
status(error.code)
|
25
|
+
do_response({:status => "error", :message => error.message},nil)
|
26
|
+
end
|
27
|
+
|
28
|
+
# get application list
|
29
|
+
get '/v1/applications' do
|
30
|
+
email = params[:email]
|
31
|
+
protected! unless email
|
32
|
+
data = []
|
33
|
+
|
34
|
+
result = @application_manager.list(email)
|
35
|
+
|
36
|
+
result.each do |app|
|
37
|
+
data << app.to_hash
|
38
|
+
end
|
39
|
+
if email
|
40
|
+
do_response(data, :list)
|
41
|
+
else
|
42
|
+
do_response(data, :list, :review => true)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
get '/' do
|
47
|
+
redirect to('/v1/applications/default')
|
48
|
+
end
|
49
|
+
|
50
|
+
# check project name
|
51
|
+
post '/v1/applications/check' do
|
52
|
+
if project = params[:project]
|
53
|
+
result = @application_manager.existed_tenant?(project)
|
54
|
+
do_response(!result, nil)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
# get an application detail
|
59
|
+
get '/v1/applications/:id' do
|
60
|
+
if(params[:id] == "default")
|
61
|
+
do_response(@application_manager.default, :apply)
|
62
|
+
else
|
63
|
+
application = @application_manager.show(params[:id])
|
64
|
+
if("true" == params[:review])
|
65
|
+
protected!
|
66
|
+
do_response(application.to_hash, :review)
|
67
|
+
else
|
68
|
+
do_response(application.to_hash, :view)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
# create an application
|
74
|
+
post '/v1/applications' do
|
75
|
+
app_info = Yajl.load(request.body.read)
|
76
|
+
puts app_info
|
77
|
+
if app_info.kind_of?(Hash) && app_info['settings'].kind_of?(Hash)
|
78
|
+
default = Yajl::load(@application_manager.default[:settings])
|
79
|
+
settings = default.merge(app_info['settings'])
|
80
|
+
app_info[:settings] = json(settings)
|
81
|
+
end
|
82
|
+
application = @application_manager.create(app_info)
|
83
|
+
app_info = application.to_hash
|
84
|
+
do_response(app_info, nil)
|
85
|
+
end
|
86
|
+
|
87
|
+
# approve an application
|
88
|
+
post '/v1/applications/:id/approve' do
|
89
|
+
protected!
|
90
|
+
result = @application_manager.approve(params[:id])
|
91
|
+
do_response(result.to_hash, nil)
|
92
|
+
end
|
93
|
+
|
94
|
+
# refuse an application
|
95
|
+
post '/v1/applications/:id/refuse' do
|
96
|
+
protected!
|
97
|
+
body = Yajl.load(request.body.read)
|
98
|
+
comments = nil
|
99
|
+
comments = body['comments'] if body && body['comments']
|
100
|
+
result = @application_manager.refuse(params[:id], comments)
|
101
|
+
do_response(result.to_hash, nil)
|
102
|
+
end
|
103
|
+
|
104
|
+
|
105
|
+
def initialize
|
106
|
+
super
|
107
|
+
@logger = Ocp::Registry.logger
|
108
|
+
@users = Set.new
|
109
|
+
@users << [Ocp::Registry.http_user, Ocp::Registry.http_password]
|
110
|
+
@application_manager = Ocp::Registry.application_manager
|
111
|
+
end
|
112
|
+
|
113
|
+
private
|
114
|
+
|
115
|
+
def do_response(data, view = nil, mark = nil)
|
116
|
+
if request.accept?('application/json') || view.nil? || (data.is_a?(Hash)&&'error' == data[:status])
|
117
|
+
json(data)
|
118
|
+
else
|
119
|
+
erb :base do
|
120
|
+
erb view ,:locals => {:data => data ,:mark => mark}
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
end
|
125
|
+
|
126
|
+
def protected!
|
127
|
+
unless authorized?
|
128
|
+
headers("WWW-Authenticate" => 'Basic realm="OCP Registry"')
|
129
|
+
halt(401, json("message" => "access_denied"))
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
def authorized?
|
134
|
+
@auth ||= Rack::Auth::Basic::Request.new(request.env)
|
135
|
+
@auth.provided? &&
|
136
|
+
@auth.basic? &&
|
137
|
+
@auth.credentials &&
|
138
|
+
@users.include?(@auth.credentials)
|
139
|
+
end
|
140
|
+
|
141
|
+
def json(payload)
|
142
|
+
Yajl::Encoder.encode(payload)
|
143
|
+
end
|
144
|
+
|
145
|
+
end
|
146
|
+
end
|