58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/legion/api/marketplace.rb', line 58
def self.register_review_actions(app) app.post '/api/marketplace/:name/submit' do
begin
Legion::Registry.submit_for_review(params[:name])
rescue ArgumentError => e
Legion::Logging.warn "API POST /api/marketplace/#{params[:name]}/submit: #{e.message}" if defined?(Legion::Logging)
halt 404, { 'Content-Type' => 'application/json' },
Legion::JSON.dump({ error: { code: 'not_found', message: e.message } })
end
json_response({ name: params[:name], status: 'pending_review' }, status_code: 202)
end
app.post '/api/marketplace/:name/approve' do
body = parse_request_body
begin
Legion::Registry.approve(params[:name], notes: body[:notes])
rescue ArgumentError => e
Legion::Logging.warn "API POST /api/marketplace/#{params[:name]}/approve: #{e.message}" if defined?(Legion::Logging)
halt 404, { 'Content-Type' => 'application/json' },
Legion::JSON.dump({ error: { code: 'not_found', message: e.message } })
end
entry = Legion::Registry.lookup(params[:name])
json_response({ name: params[:name], status: 'approved', entry: entry.to_h })
end
app.post '/api/marketplace/:name/reject' do
body = parse_request_body
begin
Legion::Registry.reject(params[:name], reason: body[:reason])
rescue ArgumentError => e
Legion::Logging.warn "API POST /api/marketplace/#{params[:name]}/reject: #{e.message}" if defined?(Legion::Logging)
halt 404, { 'Content-Type' => 'application/json' },
Legion::JSON.dump({ error: { code: 'not_found', message: e.message } })
end
entry = Legion::Registry.lookup(params[:name])
json_response({ name: params[:name], status: 'rejected', entry: entry.to_h })
end
app.post '/api/marketplace/:name/deprecate' do
body = parse_request_body
sunset = begin
body[:sunset_date] ? Date.parse(body[:sunset_date].to_s) : nil
rescue ArgumentError => e
Legion::Logging.debug "Marketplace#deprecate invalid sunset_date '#{body[:sunset_date]}': #{e.message}" if defined?(Legion::Logging)
nil
end
begin
Legion::Registry.deprecate(params[:name], successor: body[:successor], sunset_date: sunset)
rescue ArgumentError => e
Legion::Logging.warn "API POST /api/marketplace/#{params[:name]}/deprecate: #{e.message}" if defined?(Legion::Logging)
halt 404, { 'Content-Type' => 'application/json' },
Legion::JSON.dump({ error: { code: 'not_found', message: e.message } })
end
entry = Legion::Registry.lookup(params[:name])
json_response({ name: params[:name], status: 'deprecated', entry: entry.to_h })
end
end
|