tim 0.0.1
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/MIT-LICENSE +20 -0
- data/README.rdoc +392 -0
- data/Rakefile +33 -0
- data/app/assets/javascripts/tim/application.js +15 -0
- data/app/assets/stylesheets/tim/application.css +13 -0
- data/app/controllers/tim/application_controller.rb +19 -0
- data/app/controllers/tim/base_images_controller.rb +59 -0
- data/app/controllers/tim/entrypoint_controller.rb +8 -0
- data/app/controllers/tim/image_versions_controller.rb +48 -0
- data/app/controllers/tim/provider_images_controller.rb +59 -0
- data/app/controllers/tim/target_images_controller.rb +61 -0
- data/app/controllers/tim/templates_controller.rb +47 -0
- data/app/filters/tim/user_keys_filter.rb +59 -0
- data/app/helpers/tim/application_helper.rb +4 -0
- data/app/models/tim/base.rb +6 -0
- data/app/models/tim/base_image.rb +15 -0
- data/app/models/tim/image_version.rb +13 -0
- data/app/models/tim/provider_image.rb +51 -0
- data/app/models/tim/target_image.rb +50 -0
- data/app/models/tim/template.rb +19 -0
- data/app/responders/tim/custom_responder.rb +24 -0
- data/app/validators/template_validator.rb +15 -0
- data/app/views/layouts/tim/application.html.erb +14 -0
- data/app/views/tim/base_images/_base_image.xml.haml +11 -0
- data/app/views/tim/base_images/_base_image_minimal.xml.haml +2 -0
- data/app/views/tim/base_images/_form.html.erb +17 -0
- data/app/views/tim/base_images/edit.html.erb +6 -0
- data/app/views/tim/base_images/index.html.erb +17 -0
- data/app/views/tim/base_images/index.xml.haml +4 -0
- data/app/views/tim/base_images/new.html.erb +5 -0
- data/app/views/tim/base_images/show.html.erb +5 -0
- data/app/views/tim/base_images/show.xml.haml +2 -0
- data/app/views/tim/entrypoint/index.xml.haml +7 -0
- data/app/views/tim/image_versions/_form.html.erb +17 -0
- data/app/views/tim/image_versions/_image_version.xml.haml +9 -0
- data/app/views/tim/image_versions/_image_version_minimal.xml.haml +2 -0
- data/app/views/tim/image_versions/edit.html.erb +6 -0
- data/app/views/tim/image_versions/index.html.erb +17 -0
- data/app/views/tim/image_versions/index.xml.haml +4 -0
- data/app/views/tim/image_versions/new.html.erb +5 -0
- data/app/views/tim/image_versions/show.html.erb +5 -0
- data/app/views/tim/image_versions/show.xml.haml +2 -0
- data/app/views/tim/images/_form.html.erb +17 -0
- data/app/views/tim/images/edit.html.erb +6 -0
- data/app/views/tim/images/index.html.erb +21 -0
- data/app/views/tim/images/new.html.erb +5 -0
- data/app/views/tim/images/show.html.erb +5 -0
- data/app/views/tim/layouts/application.html.erb +14 -0
- data/app/views/tim/provider_images/_form.html.erb +17 -0
- data/app/views/tim/provider_images/_provider_image.xml.haml +12 -0
- data/app/views/tim/provider_images/_provider_image_minimal.xml.haml +2 -0
- data/app/views/tim/provider_images/edit.html.erb +6 -0
- data/app/views/tim/provider_images/index.html.erb +17 -0
- data/app/views/tim/provider_images/index.xml.haml +4 -0
- data/app/views/tim/provider_images/new.html.erb +5 -0
- data/app/views/tim/provider_images/show.html.erb +5 -0
- data/app/views/tim/provider_images/show.xml.haml +2 -0
- data/app/views/tim/target_images/_form.html.erb +17 -0
- data/app/views/tim/target_images/_target_image.xml.haml +13 -0
- data/app/views/tim/target_images/_target_image_minimal.xml.haml +2 -0
- data/app/views/tim/target_images/edit.html.erb +6 -0
- data/app/views/tim/target_images/index.html.erb +21 -0
- data/app/views/tim/target_images/index.xml.haml +4 -0
- data/app/views/tim/target_images/new.html.erb +5 -0
- data/app/views/tim/target_images/show.html.erb +5 -0
- data/app/views/tim/target_images/show.xml.haml +2 -0
- data/app/views/tim/templates/_form.html.erb +17 -0
- data/app/views/tim/templates/_template.xml.haml +8 -0
- data/app/views/tim/templates/_template_minimal.xml.haml +2 -0
- data/app/views/tim/templates/edit.html.erb +6 -0
- data/app/views/tim/templates/index.html.erb +17 -0
- data/app/views/tim/templates/index.xml.haml +4 -0
- data/app/views/tim/templates/new.html.erb +5 -0
- data/app/views/tim/templates/show.html.erb +5 -0
- data/app/views/tim/templates/show.xml.haml +2 -0
- data/config/cucumber.yml +8 -0
- data/config/initializers/haml.rb +1 -0
- data/config/routes.rb +9 -0
- data/config/schemas/tdl.rng +282 -0
- data/config/user_keys.yml +26 -0
- data/db/migrate/20120906180351_create_tim_base_images.rb +12 -0
- data/db/migrate/20120906210106_create_tim_image_versions.rb +10 -0
- data/db/migrate/20120910175233_create_tim_templates.rb +9 -0
- data/db/migrate/20120911202321_create_tim_target_images.rb +14 -0
- data/db/migrate/20120911204329_create_tim_provider_images.rb +19 -0
- data/lib/generators/tim/install_generator.rb +15 -0
- data/lib/generators/tim/templates/README +6 -0
- data/lib/generators/tim/templates/tim.rb +8 -0
- data/lib/image_factory/image_factory.rb +4 -0
- data/lib/image_factory/model/base.rb +88 -0
- data/lib/image_factory/model/provider_image.rb +6 -0
- data/lib/image_factory/model/target_image.rb +6 -0
- data/lib/tasks/cucumber.rake +59 -0
- data/lib/tasks/tim_tasks.rake +4 -0
- data/lib/tim.rb +8 -0
- data/lib/tim/engine.rb +9 -0
- data/lib/tim/version.rb +3 -0
- data/spec/controllers/base_images_controller_spec.rb +131 -0
- data/spec/controllers/entrypoint_controller_spec.rb +32 -0
- data/spec/controllers/image_versions_controller_spec.rb +146 -0
- data/spec/controllers/provider_images_controller_spec.rb +156 -0
- data/spec/controllers/target_images_controller_spec.rb +153 -0
- data/spec/controllers/templates_controller_spec.rb +41 -0
- data/spec/decorators/controllers/templates_controller_decorator_spec.rb +13 -0
- data/spec/factories/tim/base_image.rb +10 -0
- data/spec/factories/tim/image_factory/provider_image.rb +10 -0
- data/spec/factories/tim/image_factory/status_detail.rb +0 -0
- data/spec/factories/tim/image_factory/target_image.rb +7 -0
- data/spec/factories/tim/image_version.rb +20 -0
- data/spec/factories/tim/provider_image.rb +9 -0
- data/spec/factories/tim/target_image.rb +10 -0
- data/spec/factories/tim/template.rb +23 -0
- data/spec/filters/user_keys_filter_spec.rb +41 -0
- data/spec/fixtures/template.xml +13 -0
- data/spec/models/base_image_spec.rb +39 -0
- data/spec/models/dummy/pool_family_spec.rb +14 -0
- data/spec/models/dummy/provider_account_spec.rb +18 -0
- data/spec/models/dummy/provider_type_spec.rb +18 -0
- data/spec/models/dummy/user_spec.rb +14 -0
- data/spec/models/image_version_spec.rb +27 -0
- data/spec/models/provider_image_spec.rb +69 -0
- data/spec/models/target_image_spec.rb +75 -0
- data/spec/models/template_spec.rb +16 -0
- data/spec/spec_helper.rb +56 -0
- data/spec/support/routes.rb +41 -0
- data/spec/validators/template_validator_spec.rb +19 -0
- data/spec/views/base_images_spec.rb +23 -0
- data/spec/views/image_versions_spec.rb +25 -0
- data/spec/views/provider_images_spec.rb +30 -0
- data/spec/views/target_images_spec.rb +25 -0
- data/spec/views/templates_spec.rb +24 -0
- data/test/dummy/Rakefile +7 -0
- data/test/dummy/app/assets/javascripts/application.js +15 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/controllers/application_controller.rb +3 -0
- data/test/dummy/app/decorators/tim/controllers/templates_controller_decorator.rb +8 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/models/pool_family.rb +3 -0
- data/test/dummy/app/models/provider_account.rb +3 -0
- data/test/dummy/app/models/provider_type.rb +3 -0
- data/test/dummy/app/models/tim/base_image.rb +6 -0
- data/test/dummy/app/models/user.rb +3 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/tim/base_images/_custom.xml.haml +1 -0
- data/test/dummy/app/views/tim/image_versions/_custom.xml.haml +1 -0
- data/test/dummy/app/views/tim/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/tim/provider_images/_custom.xml.haml +1 -0
- data/test/dummy/app/views/tim/target_images/_custom.xml.haml +1 -0
- data/test/dummy/app/views/tim/templates/_custom.xml.haml +1 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/config/application.rb +58 -0
- data/test/dummy/config/boot.rb +10 -0
- data/test/dummy/config/database.yml +28 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +37 -0
- data/test/dummy/config/environments/production.rb +67 -0
- data/test/dummy/config/environments/test.rb +37 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/inflections.rb +15 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +7 -0
- data/test/dummy/config/initializers/session_store.rb +8 -0
- data/test/dummy/config/initializers/tim.rb +8 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +5 -0
- data/test/dummy/config/routes.rb +4 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20120326103723532622_create_users.rb +9 -0
- data/test/dummy/db/migrate/20120423123114264114_create_pool_families.rb +7 -0
- data/test/dummy/db/migrate/20120911182850_add_pool_family_id_to_tim_base_image.rb +5 -0
- data/test/dummy/db/migrate/20120911202845_add_provider_type_id_to_tim_target_image.rb +5 -0
- data/test/dummy/db/migrate/20120911203222_create_provider_types.rb +7 -0
- data/test/dummy/db/migrate/20120911205431_create_provider_accounts.rb +7 -0
- data/test/dummy/db/schema.rb +86 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +982 -0
- data/test/dummy/log/test.log +8629 -0
- data/test/dummy/public/404.html +26 -0
- data/test/dummy/public/422.html +26 -0
- data/test/dummy/public/500.html +26 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/script/rails +6 -0
- data/test/dummy/test.rb +0 -0
- data/test/dummy/tmp/cache/assets/C7A/BB0/sprockets%2F13445f7a19078dd2df39517062aa6711 +0 -0
- data/test/dummy/tmp/cache/assets/C8C/CC0/sprockets%2F95d79f3b3096348427f3e4e38b5202e3 +0 -0
- data/test/dummy/tmp/cache/assets/CB0/2B0/sprockets%2F79106b90879c02a115d7f6f1c8390ac4 +0 -0
- data/test/dummy/tmp/cache/assets/CE0/690/sprockets%2F04c628c2a636286bfa92a4966b82b92a +0 -0
- data/test/dummy/tmp/cache/assets/D03/040/sprockets%2Fd9e94204d4b307145f12efc109b16c1f +0 -0
- data/test/dummy/tmp/cache/assets/D06/DC0/sprockets%2Fcd282851b6e4c463409ba3ece67e0510 +0 -0
- data/test/dummy/tmp/cache/assets/D23/5F0/sprockets%2F2a521f3183c6bbcd71bd26a5490b201e +0 -0
- data/test/dummy/tmp/cache/assets/D64/3A0/sprockets%2F56ac1aed10c39b12a88cb1b30f668f58 +0 -0
- data/test/dummy/tmp/cache/assets/D69/BD0/sprockets%2F0aaf75cf34556b33a9fec534fe4d0415 +0 -0
- data/test/dummy/tmp/cache/assets/D87/D80/sprockets%2Fefa3c8b210e87358c7add88cd6f49597 +0 -0
- data/test/dummy/tmp/cache/assets/D89/200/sprockets%2Ff9b4e953c874ed6a87de6490d055d9db +0 -0
- data/test/dummy/tmp/cache/assets/DF4/430/sprockets%2F403bb1de60cae4325cebd7e6c389b8ad +0 -0
- data/test/dummy/tmp/cache/assets/E00/500/sprockets%2Faaddc5b6f2cb6b98930cc54cf4c64a95 +0 -0
- data/test/dummy/tmp/cache/assets/EB3/CE0/sprockets%2Fd75a89c9fffacd99bce7eed96844eafc +0 -0
- metadata +432 -0
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/*
|
|
2
|
+
* This is a manifest file that'll be compiled into application.css, which will include all the files
|
|
3
|
+
* listed below.
|
|
4
|
+
*
|
|
5
|
+
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
|
6
|
+
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
|
7
|
+
*
|
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the top of the
|
|
9
|
+
* compiled file, but it's generally better to create a new file per style scope.
|
|
10
|
+
*
|
|
11
|
+
*= require_self
|
|
12
|
+
*= require_tree .
|
|
13
|
+
*/
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
module Tim
|
|
2
|
+
class ApplicationController < ::ApplicationController
|
|
3
|
+
protect_from_forgery
|
|
4
|
+
|
|
5
|
+
respond_to :html, :xml
|
|
6
|
+
|
|
7
|
+
self.responder = CustomResponder
|
|
8
|
+
|
|
9
|
+
# FIXME Remove filter once support for custom XML with nested resources is
|
|
10
|
+
# supported by rails.
|
|
11
|
+
before_filter UserKeysFilter, :only => [:create, :update]
|
|
12
|
+
|
|
13
|
+
rescue_from ActiveRecord::RecordNotFound, :with => :render_not_found
|
|
14
|
+
|
|
15
|
+
def render_not_found
|
|
16
|
+
render :nothing => true, :status => :not_found
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
require 'nokogiri'
|
|
2
|
+
|
|
3
|
+
module Tim
|
|
4
|
+
class BaseImagesController < Tim::ApplicationController
|
|
5
|
+
append_before_filter :set_template_xml, :only => [:create, :update]
|
|
6
|
+
|
|
7
|
+
def index
|
|
8
|
+
@base_images = Tim::BaseImage.all unless defined? @base_images
|
|
9
|
+
respond_with @base_images
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def show
|
|
13
|
+
@base_image = Tim::BaseImage.find(params[:id]) unless defined? @base_image
|
|
14
|
+
respond_with @base_image
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def new
|
|
18
|
+
@base_image = Tim::BaseImage.new
|
|
19
|
+
respond_with @base_image
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def edit
|
|
23
|
+
@base_image = Tim::BaseImage.find(params[:id]) unless defined? @base_image
|
|
24
|
+
respond_with @base_image
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def create
|
|
28
|
+
@base_image = Tim::BaseImage.new(params[:base_image]) unless defined? @base_image
|
|
29
|
+
if @base_image.save
|
|
30
|
+
flash[:notice] = "Successfully created Base Image"
|
|
31
|
+
end
|
|
32
|
+
respond_with @base_image
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def update
|
|
36
|
+
@base_image = Tim::BaseImage.find(params[:id]) unless defined? @base_image
|
|
37
|
+
if @base_image.update_attributes(params[:base_image])
|
|
38
|
+
flash[:notice] = "Successfully updated Base Image"
|
|
39
|
+
end
|
|
40
|
+
respond_with @base_image
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def destroy
|
|
44
|
+
@base_image = Tim::BaseImage.find(params[:id]) unless defined? @base_image
|
|
45
|
+
@base_image.destroy
|
|
46
|
+
respond_with(@base_image)
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
private
|
|
50
|
+
# Handles the cases when the template xml is supplied within request
|
|
51
|
+
def set_template_xml
|
|
52
|
+
doc = ::Nokogiri::XML request.body.read
|
|
53
|
+
if !doc.xpath("//base_image/template").empty?
|
|
54
|
+
params[:base_image][:template] = { :xml => doc.xpath("//base_image/template").children.to_s}
|
|
55
|
+
end
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
module Tim
|
|
2
|
+
class ImageVersionsController < Tim::ApplicationController
|
|
3
|
+
|
|
4
|
+
def index
|
|
5
|
+
@image_versions = Tim::ImageVersion.all unless defined? @image_versions
|
|
6
|
+
respond_with @image_versions
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def show
|
|
10
|
+
@image_version = Tim::ImageVersion.find(params[:id]) unless defined? @image_version
|
|
11
|
+
respond_with @image_version
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def new
|
|
15
|
+
@image_version = Tim::ImageVersion.new unless defined? @image_version
|
|
16
|
+
@image_version = Tim::ImageVersion.new
|
|
17
|
+
respond_with @image_version
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def edit
|
|
21
|
+
@image_version = Tim::ImageVersion.find(params[:id]) unless defined? @image_version
|
|
22
|
+
respond_with @image_version
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def create
|
|
26
|
+
@image_version = ImageVersion.new(params[:image_version]) unless defined? @image_version
|
|
27
|
+
if @image_version.save
|
|
28
|
+
flash[:notice] = 'Image version was successfully created.'
|
|
29
|
+
end
|
|
30
|
+
respond_with @image_version
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def update
|
|
34
|
+
@image_version = Tim::ImageVersion.find(params[:id]) unless defined? @image_version
|
|
35
|
+
if @image_version.update_attributes(params[:image_version])
|
|
36
|
+
flash[:notice] = 'Image version was successfully updated.'
|
|
37
|
+
end
|
|
38
|
+
respond_with @image_version
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def destroy
|
|
42
|
+
@image_version = Tim::ImageVersion.find(params[:id]) unless defined? @image_version
|
|
43
|
+
@image_version.destroy
|
|
44
|
+
respond_with @image_version
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
end
|
|
48
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
module Tim
|
|
2
|
+
class ProviderImagesController < Tim::ApplicationController
|
|
3
|
+
respond_to :json, :only => :update
|
|
4
|
+
|
|
5
|
+
before_filter :factory_keys, :only => :update
|
|
6
|
+
|
|
7
|
+
def index
|
|
8
|
+
@provider_images = Tim::ProviderImage.all unless defined? @provider_images
|
|
9
|
+
respond_with @provider_images
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def show
|
|
13
|
+
@provider_image = Tim::ProviderImage.find(params[:id]) unless defined? @provider_image
|
|
14
|
+
respond_with @provider_image
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def new
|
|
18
|
+
@provider_image = Tim::ProviderImage.new
|
|
19
|
+
respond_with @provider_image
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def edit
|
|
23
|
+
@provider_image = Tim::ProviderImage.find(params[:id]) unless defined? @provider_image
|
|
24
|
+
respond_with @provider_image
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def create
|
|
28
|
+
@provider_image = ProviderImage.new(params[:provider_image]) unless defined? @provider_image
|
|
29
|
+
if @provider_image.save
|
|
30
|
+
flash[:notice] = 'Image version was successfully created.'
|
|
31
|
+
end
|
|
32
|
+
respond_with @provider_image
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def update
|
|
36
|
+
@provider_image = Tim::ProviderImage.find(params[:id]) unless defined? @provider_image
|
|
37
|
+
if @provider_image.update_attributes(params[:provider_image])
|
|
38
|
+
flash[:notice] = 'Provider image was successfully updated.'
|
|
39
|
+
end
|
|
40
|
+
respond_with @provider_image
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def destroy
|
|
44
|
+
@provider_image = Tim::ProviderImage.find(params[:id]) unless defined? @provider_image
|
|
45
|
+
@provider_image.destroy
|
|
46
|
+
respond_with @provider_image
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
private
|
|
50
|
+
# TODO Add factory permission check
|
|
51
|
+
def factory_keys
|
|
52
|
+
if params[:provider_image][:percent_complete] && params[:provider_image][:status_detail][:activity]
|
|
53
|
+
params[:provider_image] = { :progress => params[:provider_image][:percent_complete],
|
|
54
|
+
:status_detail => params[:provider_image][:status_detail][:activity],
|
|
55
|
+
:status => params[:provider_image][:status] }
|
|
56
|
+
end
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
module Tim
|
|
2
|
+
class TargetImagesController < Tim::ApplicationController
|
|
3
|
+
respond_to :json, :only => :update
|
|
4
|
+
|
|
5
|
+
before_filter :factory_keys, :only => :update
|
|
6
|
+
|
|
7
|
+
def index
|
|
8
|
+
@target_images = Tim::TargetImage.all unless defined? @target_images
|
|
9
|
+
respond_with @target_images
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def show
|
|
13
|
+
@target_image = Tim::TargetImage.find(params[:id]) unless defined? @target_image
|
|
14
|
+
respond_with @target_image
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def new
|
|
18
|
+
@target_image = Tim::TargetImage.new unless defined? @target_image
|
|
19
|
+
respond_with @target_image
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def edit
|
|
23
|
+
@target_image = Tim::TargetImage.find(params[:id]) unless defined? @target_image
|
|
24
|
+
respond_with @target_image
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def create
|
|
28
|
+
@target_image = TargetImage.new(params[:target_image]) unless defined? @target_image
|
|
29
|
+
if @target_image.save
|
|
30
|
+
flash[:notice] = 'Image version was successfully created.'
|
|
31
|
+
end
|
|
32
|
+
respond_with @target_image
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def update
|
|
36
|
+
@target_image = Tim::TargetImage.find(params[:id]) unless defined? @target_image
|
|
37
|
+
if @target_image.update_attributes(params[:target_image])
|
|
38
|
+
flash[:notice] = 'Target image was successfully updated.'
|
|
39
|
+
end
|
|
40
|
+
respond_with @target_image
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# DELETE /target_images/1
|
|
44
|
+
# DELETE /target_images/1.xml
|
|
45
|
+
def destroy
|
|
46
|
+
@target_image = Tim::TargetImage.find(params[:id]) unless defined? @target_image
|
|
47
|
+
@target_image.destroy
|
|
48
|
+
respond_with @target_image
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# TODO Add factory permission check
|
|
52
|
+
def factory_keys
|
|
53
|
+
if params[:target_image][:percent_complete] && params[:target_image][:status_detail][:activity]
|
|
54
|
+
params[:target_image] = { :progress => params[:target_image][:percent_complete],
|
|
55
|
+
:status_detail => params[:target_image][:status_detail][:activity],
|
|
56
|
+
:status => params[:target_image][:status] }
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
module Tim
|
|
2
|
+
class TemplatesController < Tim::ApplicationController
|
|
3
|
+
|
|
4
|
+
def index
|
|
5
|
+
@templates = Tim::Template.all unless defined? @templates
|
|
6
|
+
respond_with @templates
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
def show
|
|
10
|
+
@template = Tim::Template.find(params[:id]) unless defined? @template
|
|
11
|
+
respond_with @template
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def new
|
|
15
|
+
@template = Tim::Template.new unless defined? @template
|
|
16
|
+
respond_with @template
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def edit
|
|
20
|
+
@template = Tim::Template.find(params[:id])
|
|
21
|
+
respond_with @template
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def create
|
|
25
|
+
@template = Tim::Template.new(params[:template]) unless defined? @template
|
|
26
|
+
if @template.save
|
|
27
|
+
flash[:notice] = 'Template was successfully created.'
|
|
28
|
+
end
|
|
29
|
+
respond_with @template
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def update
|
|
33
|
+
@template = Tim::Template.find(params[:id]) unless defined? @template
|
|
34
|
+
if @template.update_attributes(params[:template])
|
|
35
|
+
flash[:notice] = 'Template was successfully updated.'
|
|
36
|
+
end
|
|
37
|
+
respond_with @template
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def destroy
|
|
41
|
+
@template = Tim::Template.find(params[:id]) unless defined? @template
|
|
42
|
+
@template.destroy
|
|
43
|
+
respond_with @template
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
end
|
|
47
|
+
end
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# FIXME Remove replace_user_keys(map) once support for custom XML with nested
|
|
2
|
+
# resources is supported.
|
|
3
|
+
|
|
4
|
+
module Tim
|
|
5
|
+
class UserKeysFilter
|
|
6
|
+
|
|
7
|
+
@@user_keys = YAML.load(File.read(File.join(Tim::Engine.root, "config", "user_keys.yml")))
|
|
8
|
+
|
|
9
|
+
def self.before(controller)
|
|
10
|
+
if controller.request.format == "application/xml"
|
|
11
|
+
begin
|
|
12
|
+
@controller = controller
|
|
13
|
+
resource_name = @controller.controller_name.singularize.to_sym
|
|
14
|
+
set_template_params(resource_name)
|
|
15
|
+
@controller.params[resource_name] = replace_user_keys(@controller.params[resource_name], @@user_keys[resource_name])
|
|
16
|
+
rescue => e
|
|
17
|
+
@controller.head :unprocessable_entity
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Replaces all instances of user keys with those defined in @@user_keys
|
|
23
|
+
# Supports N levels of nested maps.
|
|
24
|
+
def self.replace_user_keys(map, user_keys)
|
|
25
|
+
modified_map = map.clone
|
|
26
|
+
map.each_pair do |key, value|
|
|
27
|
+
# Sets the full template XML in the template.xml attribute
|
|
28
|
+
if key == "template" || key == :template
|
|
29
|
+
modified_map[key] = { :xml => template_xml }
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
if user_keys.has_key? key
|
|
33
|
+
if map[key].instance_of? Hash
|
|
34
|
+
# FIXME Using recursion in this way increases heap memory usage.
|
|
35
|
+
# If we decide to stick with this approach a more memory efficient
|
|
36
|
+
# implementation should be considered.
|
|
37
|
+
modified_map[key] = replace_user_keys(map[key], user_keys)
|
|
38
|
+
elsif map[key].instance_of? Array
|
|
39
|
+
modified_map[key] = map[key].collect { |v| replace_user_keys(v, user_keys)}
|
|
40
|
+
end
|
|
41
|
+
modified_map[user_keys[key]] = modified_map.delete(key)
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
modified_map
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# We are storing raw XML in the templates.xml attributes. Therefore we
|
|
48
|
+
# must retrieve the raw XML from the request body.
|
|
49
|
+
def self.set_template_params(resource_name)
|
|
50
|
+
if resource_name == :template
|
|
51
|
+
@controller.params[:template] = { :xml => template_xml }
|
|
52
|
+
end
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def self.template_xml
|
|
56
|
+
::Nokogiri::XML(@controller.request.body.read).xpath("//template").to_xml
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
module Tim
|
|
2
|
+
class BaseImage < Tim::Base
|
|
3
|
+
has_many :image_versions
|
|
4
|
+
belongs_to :template
|
|
5
|
+
belongs_to :user, :class_name => Tim.user_class
|
|
6
|
+
|
|
7
|
+
accepts_nested_attributes_for :template
|
|
8
|
+
accepts_nested_attributes_for :image_versions
|
|
9
|
+
|
|
10
|
+
attr_accessible :template, :name, :description
|
|
11
|
+
attr_accessible :template_attributes
|
|
12
|
+
attr_accessible :image_versions_attributes, :as => :admin
|
|
13
|
+
attr_protected :id
|
|
14
|
+
end
|
|
15
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module Tim
|
|
2
|
+
class ImageVersion < Tim::Base
|
|
3
|
+
belongs_to :base_image
|
|
4
|
+
has_many :target_images
|
|
5
|
+
|
|
6
|
+
accepts_nested_attributes_for :base_image
|
|
7
|
+
accepts_nested_attributes_for :target_images
|
|
8
|
+
|
|
9
|
+
attr_accessible :base_image_attributes
|
|
10
|
+
attr_accessible :target_images_versions_attributes
|
|
11
|
+
attr_protected :id
|
|
12
|
+
end
|
|
13
|
+
end
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
module Tim
|
|
2
|
+
class ProviderImage < Tim::Base
|
|
3
|
+
belongs_to :target_image
|
|
4
|
+
belongs_to :provider_account, :class_name => Tim.provider_account_class
|
|
5
|
+
|
|
6
|
+
accepts_nested_attributes_for :target_image
|
|
7
|
+
|
|
8
|
+
attr_accessible :target_image_attributes
|
|
9
|
+
attr_accessible :status, :status_detail, :progress #, :as => :image_factory
|
|
10
|
+
attr_accessible :provider
|
|
11
|
+
attr_writer :credentials
|
|
12
|
+
attr_protected :id
|
|
13
|
+
|
|
14
|
+
after_create :create_factory_provider_image
|
|
15
|
+
|
|
16
|
+
private
|
|
17
|
+
def create_factory_provider_image
|
|
18
|
+
begin
|
|
19
|
+
provider_image = ImageFactory::ProviderImage.new(:target_image_id => self.target_image.factory_id,
|
|
20
|
+
:provider => self.provider,
|
|
21
|
+
:credentials => @credentials,
|
|
22
|
+
# TODO Remove this when upgrading to 3.2
|
|
23
|
+
# target conflicts with rails 3.0.10
|
|
24
|
+
# ActiveRecord::Associations::Association#target
|
|
25
|
+
:target => target_image.target,
|
|
26
|
+
:parameters => "")
|
|
27
|
+
# TODO There is a bug in ARes 3.0.10 that will add map name twice when setting in mass assign. So we set
|
|
28
|
+
# parameters separately.
|
|
29
|
+
# Setting parameters at mass assign results in json => {"target_image":"parameters":{"parameters":{"..."}}}"
|
|
30
|
+
# This should be tested and removed if fixed in 3.2
|
|
31
|
+
provider_image.parameters = { :callbacks => ["#{ImageFactory::ProviderImage.callback_url}/#{self.id}"] }
|
|
32
|
+
provider_image.save!
|
|
33
|
+
populate_factory_fields(provider_image)
|
|
34
|
+
self.save
|
|
35
|
+
rescue => e
|
|
36
|
+
# TODO Add proper error handling
|
|
37
|
+
raise e
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def populate_factory_fields(factory_provider_image)
|
|
42
|
+
self.status = factory_provider_image.status
|
|
43
|
+
self.factory_id = factory_provider_image.id
|
|
44
|
+
self.status_detail = factory_provider_image.status_detail.activity
|
|
45
|
+
self.progress = factory_provider_image.percent_complete
|
|
46
|
+
self.provider = factory_provider_image.provider
|
|
47
|
+
self.external_image_id = factory_provider_image.identifier_on_provider
|
|
48
|
+
self.provider_account_id = factory_provider_image.provider_account_identifier
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|