projects GET params
This commit is contained in:
parent
324d4fd581
commit
8c4453ef39
@ -50,7 +50,7 @@ module Output
|
|||||||
def json
|
def json
|
||||||
JSON.pretty_generate(case ARGV[1]
|
JSON.pretty_generate(case ARGV[1]
|
||||||
when "list"
|
when "list"
|
||||||
@list
|
@list.map {|l| l["name"]}
|
||||||
when "show"
|
when "show"
|
||||||
@show
|
@show
|
||||||
when "servers"
|
when "servers"
|
||||||
@ -63,7 +63,7 @@ module Output
|
|||||||
private
|
private
|
||||||
def create_list list
|
def create_list list
|
||||||
abort(I18n.t("output.not_found.project.list")) if list.empty?
|
abort(I18n.t("output.not_found.project.list")) if list.empty?
|
||||||
rows = list.map {|l| [l]}
|
rows = list.map {|l| [l["name"]]}
|
||||||
headers = [ I18n.t("output.table_header.id") ]
|
headers = [ I18n.t("output.table_header.id") ]
|
||||||
return headers, rows
|
return headers, rows
|
||||||
end
|
end
|
||||||
|
|||||||
@ -1,3 +1,3 @@
|
|||||||
module DevopsClient
|
module DevopsClient
|
||||||
VERSION = "2.1.32"
|
VERSION = "2.1.33"
|
||||||
end
|
end
|
||||||
|
|||||||
@ -15,16 +15,21 @@ class Project < MongoModel
|
|||||||
|
|
||||||
MULTI_TYPE = "multi"
|
MULTI_TYPE = "multi"
|
||||||
|
|
||||||
|
def self.fields
|
||||||
|
["deploy_envs", "type"]
|
||||||
|
end
|
||||||
|
|
||||||
def initialize p={}
|
def initialize p={}
|
||||||
self.id = p["name"]
|
self.id = p["name"]
|
||||||
raise InvalidRecord.new "No deploy envirenments for project #{self.id}" if p["deploy_envs"].nil? or p["deploy_envs"].empty?
|
#raise InvalidRecord.new "No deploy envirenments for project #{self.id}" if p["deploy_envs"].nil? or p["deploy_envs"].empty?
|
||||||
self.deploy_envs = []
|
|
||||||
self.type = p["type"]
|
self.type = p["type"]
|
||||||
env_class = ( self.multi? ? DeployEnvMulti : DeployEnv )
|
env_class = ( self.multi? ? DeployEnvMulti : DeployEnv )
|
||||||
|
unless p["deploy_envs"].nil?
|
||||||
p["deploy_envs"].each do |e|
|
self.deploy_envs = []
|
||||||
env = env_class.create(e)
|
p["deploy_envs"].each do |e|
|
||||||
self.deploy_envs.push env
|
env = env_class.create(e)
|
||||||
|
self.deploy_envs.push env
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -109,7 +114,8 @@ class Project < MongoModel
|
|||||||
end
|
end
|
||||||
|
|
||||||
def to_hash_without_id
|
def to_hash_without_id
|
||||||
h = {"deploy_envs" => self.deploy_envs.map {|e| e.to_hash}}
|
h = {}
|
||||||
|
h["deploy_envs"] = self.deploy_envs.map {|e| e.to_hash} unless self.deploy_envs.nil?
|
||||||
if self.multi?
|
if self.multi?
|
||||||
h["type"] = MULTI_TYPE
|
h["type"] = MULTI_TYPE
|
||||||
end
|
end
|
||||||
|
|||||||
@ -119,7 +119,7 @@ class MongoConnector
|
|||||||
p.to_a.map {|bp| Project.create_from_bson bp}
|
p.to_a.map {|bp| Project.create_from_bson bp}
|
||||||
end
|
end
|
||||||
|
|
||||||
def projects list=nil, type=nil
|
def projects list=nil, type=nil, fields=[]
|
||||||
q = (list.nil? ? {} : {"_id" => {"$in" => list}})
|
q = (list.nil? ? {} : {"_id" => {"$in" => list}})
|
||||||
case type
|
case type
|
||||||
when :multi
|
when :multi
|
||||||
@ -127,7 +127,7 @@ class MongoConnector
|
|||||||
#else
|
#else
|
||||||
# q["type"] = {"$exists" => false}
|
# q["type"] = {"$exists" => false}
|
||||||
end
|
end
|
||||||
res = @projects.find(create_query(q))
|
res = @projects.find(create_query(q), :fields => fields)
|
||||||
a = res.to_a
|
a = res.to_a
|
||||||
a.map {|bp| Project.create_from_bson bp}
|
a.map {|bp| Project.create_from_bson bp}
|
||||||
end
|
end
|
||||||
|
|||||||
@ -41,6 +41,8 @@ module Version2_0
|
|||||||
# - method : GET
|
# - method : GET
|
||||||
# - headers :
|
# - headers :
|
||||||
# - Accept: application/json
|
# - Accept: application/json
|
||||||
|
# - params :
|
||||||
|
# - deploy_envs, type
|
||||||
#
|
#
|
||||||
# * *Returns* :
|
# * *Returns* :
|
||||||
# [
|
# [
|
||||||
@ -50,7 +52,11 @@ module Version2_0
|
|||||||
get "/projects" do
|
get "/projects" do
|
||||||
check_headers :accept
|
check_headers :accept
|
||||||
check_privileges("project", "r")
|
check_privileges("project", "r")
|
||||||
json BaseRoutes.mongo.projects.map {|p| p.id}
|
fields = []
|
||||||
|
Project.fields.each do |k|
|
||||||
|
fields.push k if params.key?(k)
|
||||||
|
end
|
||||||
|
json BaseRoutes.mongo.projects(nil, nil, fields).map {|p| p.to_hash}
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get project by id
|
# Get project by id
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user