1
0
mirror of https://github.com/OpenNebula/one.git synced 2025-08-29 09:49:28 +03:00

feature #4217: Add missing files. Default ACL for marketplace and apps

This commit is contained in:
Ruben S. Montero
2015-12-11 16:10:39 +01:00
parent a4cf0cc387
commit e98b5fb2c6
6 changed files with 632 additions and 0 deletions

View File

@ -103,6 +103,15 @@ AclManager::AclManager(
AuthRequest::USE,
AclRule::ALL_ID,
error_str);
// * MARKETPLACE+MARKETPLACEAPP/* USE *
add_rule(AclRule::ALL_ID,
AclRule::ALL_ID |
PoolObjectSQL::MARKETPLACE |
PoolObjectSQL::MARKETPLACEAPP,
AuthRequest::USE,
AclRule::ALL_ID,
error_str);
}
}

View File

@ -0,0 +1,47 @@
---
:ID:
:desc: ONE identifier for the marketplace app
:size: 4
:NAME:
:desc: Name of the marketplace app
:size: 13
:left: true
:PUBLISHER:
:desc: Publisher of the marketplace app
:size: 15
:left: true
:VERSION:
:desc: Version of the marketplace app
:size: 10
:left: true
:SIZE:
:desc: Marketplace app size (M)
:size: 8
:STAT:
:desc: State of the app
:size: 4
:left: true
:DATE:
:desc: Publishing date for the marketplace app
:size: 15
:MARKET:
:desc: Name of the marketplace
:size: 10
:left: true
:default:
- :ID
- :NAME
- :PUBLISHER
- :VERSION
- :SIZE
- :STAT
- :DATE
- :MARKET

View File

@ -0,0 +1,141 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
require 'one_helper'
class OneMarketPlaceAppHelper < OpenNebulaHelper::OneHelper
def self.rname
"MARKETPLACEAPP"
end
def self.conf_file
"onemarketapp.yaml"
end
def self.state_to_str(id)
id = id.to_i
state_str = MarketPlaceApp::MARKETPLACEAPP_STATES[id]
return MarketPlaceApp::SHORT_MARKETPLACEAPP_STATES[state_str]
end
def format_pool(options)
config_file = self.class.table_conf
table = CLIHelper::ShowTable.new(config_file, self) do
column :ID, "ONE identifier for the marketplace app", :size=>4 do |d|
d["ID"]
end
column :NAME, "Name of the marketplace app", :left, :size=>13 do |d|
d["NAME"]
end
column :PUBLISHER, "Publisher of the App", :left, :size=>15 do |d|
d["PUBLISHER"]
end
column :VERSION, "Version of the app", :left, :size=>10 do |d|
d["VERSION"]
end
column :SIZE, "App size", :size =>8 do |d|
OpenNebulaHelper.unit_to_str(d['SIZE'].to_i, {}, 'M')
end
column :STAT, "State of the app", :left, :size=>4 do |d|
OneMarketPlaceAppHelper.state_to_str(d["STATE"])
end
column :DATE, "Publishing date of the app",
:size=>15 do |d|
OpenNebulaHelper.time_to_str(d["DATE"])
end
column :MARKET, "Name of the marketplace", :left, :size=>10 do |d|
d["MARKETPLACE"]
end
default :ID,:NAME,:PUBLISHER,:VERSION,:SIZE,:STAT,:DATE,:MARKET
end
table
end
private
def factory(id=nil)
if id
OpenNebula::MarketPlaceApp.new_with_id(id, @client)
else
xml=OpenNebula::MarketPlaceApp.build_xml
OpenNebula::MarketPlaceApp.new(xml, @client)
end
end
def factory_pool(user_flag=-2)
OpenNebula::MarketPlaceAppPool.new(@client, user_flag)
end
def format_resource(app, options = {})
str="%-15s: %-20s"
str_h1="%-80s"
CLIHelper.print_header(str_h1 % "MARKETPLACE APP #{app['ID']} INFORMATION")
puts str % ["ID", app.id.to_s]
puts str % ["NAME", app.name]
puts str % ["USER", app['UNAME']]
puts str % ["GROUP", app['GNAME']]
puts str % ["MARKETPLACE", app['MARKETPLACE']]
puts str % ["STATE", OneMarketPlaceAppHelper.state_to_str(app["STATE"])]
puts
CLIHelper.print_header(str_h1 % "PERMISSIONS",false)
["OWNER", "GROUP", "OTHER"].each { |e|
mask = "---"
mask[0] = "u" if app["PERMISSIONS/#{e}_U"] == "1"
mask[1] = "m" if app["PERMISSIONS/#{e}_M"] == "1"
mask[2] = "a" if app["PERMISSIONS/#{e}_A"] == "1"
puts str % [e, mask]
}
puts
CLIHelper.print_header(str_h1 % "DETAILS", false)
puts str % ["SOURCE", app['SOURCE']]
puts str % ["CHECKSUM", app['CHECKSUM']]
puts str % ["PUBLISHER", app['PUBLISHER']]
puts str % ["PUB. DATE", OpenNebulaHelper.time_to_str(app["DATE"])]
puts str % ["VERSION", app['VERSION']]
puts str % ["DESCRIPTION", app['DESCRIPTION']]
puts str % ["SIZE", OpenNebulaHelper.unit_to_str(app['SIZE'].to_i,{},'M')]
puts
CLIHelper.print_header(str_h1 % "IMPORT TEMPLATE", false)
puts Base64.decode64(app['APPTEMPLATE64'])
puts
CLIHelper.print_header(str_h1 % "MARKETPLACE APP TEMPLATE", false)
puts app.template_str
puts
end
end

193
src/cli/onemarketapp Executable file
View File

@ -0,0 +1,193 @@
#!/usr/bin/env ruby
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
ONE_LOCATION=ENV["ONE_LOCATION"]
if !ONE_LOCATION
RUBY_LIB_LOCATION="/usr/lib/one/ruby"
else
RUBY_LIB_LOCATION=ONE_LOCATION+"/lib/ruby"
end
$: << RUBY_LIB_LOCATION
$: << RUBY_LIB_LOCATION+"/cli"
require 'command_parser'
require 'one_helper/onemarketapp_helper'
require 'one_helper/onemarket_helper'
CommandParser::CmdParser.new(ARGV) do
usage "`onemarket` <command> [<args>] [<options>]"
version OpenNebulaHelper::ONE_VERSION
helper = OneMarketPlaceAppHelper.new
before_proc do
helper.set_client(options)
end
########################################################################
# Global Options
########################################################################
set :option, CommandParser::OPTIONS+OpenNebulaHelper::CLIENT_OPTIONS
list_options = CLIHelper::OPTIONS
list_options << OpenNebulaHelper::XML
list_options << OpenNebulaHelper::NUMERIC
list_options << OpenNebulaHelper::DESCRIBE
CREATE_OPTIONS = [OneMarketPlaceHelper::MARKETPLACE]
########################################################################
# Formatters for arguments
########################################################################
set :format, :groupid, OpenNebulaHelper.rname_to_id_desc("GROUP") do |arg|
OpenNebulaHelper.rname_to_id(arg, "GROUP")
end
set :format, :userid, OpenNebulaHelper.rname_to_id_desc("USER") do |arg|
OpenNebulaHelper.rname_to_id(arg, "USER")
end
set :format, :appid, OneMarketPlaceAppHelper.to_id_desc do |arg|
helper.to_id(arg)
end
set :format, :appid_list, OneMarketPlaceAppHelper.list_to_id_desc do |arg|
helper.list_to_id(arg)
end
set :format, :filterflag, OneMarketPlaceAppHelper.filterflag_to_i_desc do |arg|
helper.filterflag_to_i(arg)
end
########################################################################
# Commands
########################################################################
create_desc = <<-EOT.unindent
Creates a new marketplace app in the given marketplace
EOT
command :create, create_desc, :file, :options=>CREATE_OPTIONS do
if options[:marketplace].nil?
STDERR.puts "Marketplace to save the app is mandatory: "
STDERR.puts "\t -m marketplace_id"
exit(-1)
end
helper.create_resource(options) do |app|
begin
template=File.read(args[0])
app.allocate(template, options[:marketplace])
rescue => e
STDERR.puts e.messsage
exit(-1)
end
end
end
delete_desc = <<-EOT.unindent
Deletes the given marketplace app
EOT
command :delete, delete_desc, [:range, :appid_list] do
helper.perform_actions(args[0],options,"deleted") do |app|
app.delete
end
end
update_desc = <<-EOT.unindent
Update the template contents for the app. If a path is not provided the
editor will be launched to modify the current content.
EOT
command :update, update_desc, :appid, [:file, nil],
:options=>OpenNebulaHelper::APPEND do
helper.perform_action(args[0],options,"modified") do |obj|
if options[:append]
str = OpenNebulaHelper.append_template(args[0], obj, args[1])
else
str = OpenNebulaHelper.update_template(args[0], obj, args[1])
end
obj.update(str, options[:append])
end
end
chgrp_desc = <<-EOT.unindent
Changes the marketplace app group
EOT
command :chgrp, chgrp_desc,[:range, :appid_list], :groupid do
helper.perform_actions(args[0],options,"Group changed") do |app|
app.chown(-1, args[1].to_i)
end
end
chown_desc = <<-EOT.unindent
Changes the marketplace app owner and group
EOT
command :chown, chown_desc, [:range, :appid_list], :userid,
[:groupid,nil] do
gid = args[2].nil? ? -1 : args[2].to_i
helper.perform_actions(args[0],options,
"Owner/Group changed") do |app|
app.chown(args[1].to_i, gid)
end
end
chmod_desc = <<-EOT.unindent
Changes the marketplace app permissions
EOT
command :chmod, chmod_desc, [:range, :appid_list], :octet do
helper.perform_actions(args[0],options,
"Permissions changed") do |app|
app.chmod_octet(args[1])
end
end
rename_desc = <<-EOT.unindent
Renames the marketplace app
EOT
command :rename, rename_desc, :appid, :name do
helper.perform_action(args[0],options,"renamed") do |o|
o.rename(args[1])
end
end
list_desc = <<-EOT.unindent
Lists marketplace apps
EOT
command :list, list_desc, [:filterflag, nil], :options=>list_options do
helper.list_pool(options, false, args[0])
end
show_desc = <<-EOT.unindent
Shows information for the given marketplace app
EOT
command :show, show_desc, :appid, :options=>OpenNebulaHelper::XML do
helper.show_resource(args[0],options)
end
end

View File

@ -0,0 +1,165 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
require 'opennebula/pool_element'
module OpenNebula
class MarketPlaceApp < PoolElement
#######################################################################
# Constants and Class Methods
#######################################################################
MARKETPLACEAPP_METHODS = {
:info => "marketapp.info",
:allocate => "marketapp.allocate",
:delete => "marketapp.delete",
:update => "marketapp.update",
:chown => "marketapp.chown",
:chmod => "marketapp.chmod",
:rename => "marketapp.rename"
}
MARKETPLACEAPP_STATES=%w{INIT READY LOCKED ERROR}
SHORT_MARKETPLACEAPP_STATES={
"INIT" => "init",
"READY" => "rdy",
"LOCKED" => "lock",
"ERROR" => "err",
}
# Creates a MarketPlace description with just its identifier
# this method should be used to create plain MarketPlace objects.
# +id+ the id of the user
#
# Example:
# app = MarketPlaceApp.new(MarketPlace.build_xml(3),rpc_client)
#
def MarketPlaceApp.build_xml(pe_id=nil)
if pe_id
app_xml = "<MARKETPLACEAPP><ID>#{pe_id}</ID></MARKETPLACEAPP>"
else
app_xml = "<MARKETPLACEAPP></MARKETPLACEAPP>"
end
XMLElement.build_xml(app_xml,'MARKETPLACEAPP')
end
# Class constructor
def initialize(xml, client)
super(xml, client)
end
#######################################################################
# XML-RPC Methods for the MarketPlace Object
#######################################################################
# Retrieves the information of the given marketplace app
def info()
super(MARKETPLACEAPP_METHODS[:info], 'MARKETPLACEAPP')
end
alias_method :info!, :info
# Allocates a new MarketPlace in OpenNebula
#
# @param description [String] The template of the marketplace app
# @param mp_id [Integer] The id of the marketplace to create the app
#
# @return [Integer, OpenNebula::Error] the new ID in case of
# success, error otherwise
def allocate(description, mp_id)
super(MARKETPLACEAPP_METHODS[:allocate], description, mp_id)
end
# Deletes the marketplace app
def delete()
super(MARKETPLACEAPP_METHODS[:delete])
end
# Replaces the template contents
#
# @param new_template [String] New template contents
# @param append [true, false] True to append new attributes instead of
# replace the whole template
#
# @return [nil, OpenNebula::Error] nil in case of success, Error
# otherwise
def update(new_template, append=false)
super(MARKETPLACEAPP_METHODS[:update], new_template, append ? 1 : 0)
end
# Changes the owner/group
#
# @param uid [Integer] the new owner id. Set to -1 to leave the current one
# @param gid [Integer] the new group id. Set to -1 to leave the current one
#
# @return [nil, OpenNebula::Error] nil in case of success, Error
# otherwise
def chown(uid, gid)
super(MARKETPLACEAPP_METHODS[:chown], uid, gid)
end
# Changes the marketplace app permissions.
#
# @param octet [String] Permissions octed , e.g. 640
# @return [nil, OpenNebula::Error] nil in case of success, Error
# otherwise
def chmod_octet(octet)
super(MARKETPLACEAPP_METHODS[:chmod], octet)
end
# Changes the marketplace app permissions.
# Each [Integer] argument must be 1 to allow, 0 deny, -1 do not change
#
# @return [nil, OpenNebula::Error] nil in case of success, Error
# otherwise
def chmod(owner_u, owner_m, owner_a, group_u, group_m, group_a, other_u,
other_m, other_a)
super(MARKETPLACEAPP_METHODS[:chmod], owner_u, owner_m, owner_a, group_u,
group_m, group_a, other_u, other_m, other_a)
end
# Renames this marketplace app
#
# @param name [String] New name for the marketplace app
#
# @return [nil, OpenNebula::Error] nil in case of success, Error
# otherwise
def rename(name)
return call(MARKETPLACEAPP_METHODS[:rename], @pe_id, name)
end
# ---------------------------------------------------------------------
# Helpers to get information
# ---------------------------------------------------------------------
# Returns the state of the marketplace app (numeric value)
def state
self['STATE'].to_i
end
# Returns the state of the marketplace app (string value)
def state_str
MARKETPLACEAPP_STATES[state]
end
# Returns the state of the marketplace app (string value)
def short_state_str
SHORT_MARKETPLACEAPP_STATES[state_str]
end
end
end

View File

@ -0,0 +1,77 @@
# -------------------------------------------------------------------------- #
# Copyright 2002-2015, OpenNebula Project, OpenNebula Systems #
# #
# 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. #
#--------------------------------------------------------------------------- #
require 'opennebula/pool'
module OpenNebula
class MarketPlaceAppPool < Pool
#######################################################################
# Constants and Class attribute accessors
#######################################################################
MARKETPLACEAPP_POOL_METHODS = {
:info => "marketapppool.info"
}
#######################################################################
# Class constructor & Pool Methods
#######################################################################
# +client+ a Client object that represents a XML-RPC connection
def initialize(client, user_id=-1)
super('MARKETPLACEAPP_POOL','MARKETPLACEAPP', client)
@user_id = user_id
end
# Factory method to create MarketPlaceApp objects
def factory(element_xml)
OpenNebula::MarketPlaceApp.new(element_xml, @client)
end
#######################################################################
# XML-RPC Methods for the User Object
#######################################################################
# Retrieves all or part of the Images in the pool.
def info(*args)
case args.size
when 0
info_filter(MARKETPLACEAPP_POOL_METHODS[:info],@user_id,-1,-1)
when 3
info_filter(MARKETPLACEAPP_POOL_METHODS[:info],args[0],args[1],args[2])
end
end
def info_all()
return super(MARKETPLACEAPP_POOL_METHODS[:info])
end
def info_mine()
return super(MARKETPLACEAPP_POOL_METHODS[:info])
end
def info_group()
return super(MARKETPLACEAPP_POOL_METHODS[:info])
end
alias_method :info!, :info
alias_method :info_all!, :info_all
alias_method :info_mine!, :info_mine
alias_method :info_group!, :info_group
end
end