Attention une mise à jour du service Gitlab va être effectuée le mardi 18 janvier (et non lundi 17 comme annoncé précédemment) entre 18h00 et 18h30. Cette mise à jour va générer une interruption du service dont nous ne maîtrisons pas complètement la durée mais qui ne devrait pas excéder quelques minutes.

Commit 7f7e15a0 authored by Samir Noir's avatar Samir Noir 🧀
Browse files

Add a /latest endpoint to versions controller

parent 14c79e0b
......@@ -148,7 +148,7 @@ class ResourcesController < ApplicationController
end
def lookup_path(path, params)
object = repository.find(
object = repository.find_and_expand(
path.gsub(%r{/?platforms}, ''),
branch: params[:branch],
version: params[:version],
......
......@@ -178,6 +178,13 @@ class VersionsController < ApplicationController
render_result(output)
end
def latest
vary_on :accept; allow :get
sha = repository.find(resource_path).oid
render location: request.fullpath.gsub(/latest$/, sha), id: sha, status: 307, plain: ''
end
protected
def resource_path
......
......@@ -22,8 +22,10 @@ Api::Application.routes.draw do
resources :apidocs, only: [:index]
get '/versions' => 'versions#index'
get '/versions/latest' => 'versions#latest'
get '/versions/:id' => 'versions#show'
get '*resource/versions' => 'versions#index'
get '*resource/versions/latest' => 'versions#latest'
get '*resource/versions/:id' => 'versions#show'
resources :network_equipments, only: %i[index show]
......
......@@ -44,6 +44,21 @@ module Grid5000
@commit = find_commit_for(path, options)
return nil if @commit.nil?
logger.info " commit = #{@commit} {id: #{@commit.oid}, message: #{@commit.message.chomp}}"
rescue Rugged::Error => e
logger.debug "#{Time.now}: Got a Rugged exception #{e}"
return e
end
@commit
end
def find_and_expand(path, options = {})
begin
find(path, options)
path = full_path(path)
if @commit.nil?
return nil
end
object = find_object_at(path, @commit)
logger.debug " object = #{object}"
......
......@@ -193,7 +193,7 @@ describe SitesController do
end
it 'should fail gracefully in the event of a grit timeout' do
expect_any_instance_of(Grid5000::Repository).to receive(:find_commit_for).and_raise(Rugged::RepositoryError)
expect_any_instance_of(Grid5000::Repository).to receive(:find).and_raise(Rugged::RepositoryError)
get :status, params: { id: 'rennes', job_details: 'no', format: :json }
expect(response.status).to eq 503
end
......
......@@ -43,14 +43,14 @@ describe Grid5000::Repository do
describe 'find' do
it 'should find / element' do
object = @repository.find('grid5000')
object = @repository.find_and_expand('grid5000')
expect(object).to_not be_nil
expect(object['version']).to eq @latest_commit
end
it 'should return an exception if Rugged::PathError is raised' do
expect(@repository).to receive(:find_commit_for).and_raise(Rugged::RepositoryError)
object = @repository.find('grid5000')
expect(@repository).to receive(:find).and_raise(Rugged::RepositoryError)
object = @repository.find_and_expand('grid5000')
expect(object).to be_an(Exception)
end
end
......@@ -152,7 +152,7 @@ describe Grid5000::Repository do
describe 'expanding an object' do
it 'should expand a tree of blobs into a collection' do
result = @repository.find(
result = @repository.find_and_expand(
'grid5000/sites/grenoble/clusters/dahu/nodes'
)
expect(result).not_to be_nil
......@@ -161,7 +161,7 @@ describe Grid5000::Repository do
expect(result['items'].map { |i| i['uid'] }.first).to eq('dahu-1')
end
it 'should expand a tree of trees into a collection [sites]' do
result = @repository.find(
result = @repository.find_and_expand(
'grid5000/sites'
)
expect(result['items'].map do |i|
......@@ -171,21 +171,21 @@ describe Grid5000::Repository do
expect(result['offset']).to eq(0)
end
it "should expand a tree of blobs and trees into a resource hash resulting from the agregation of the blob's contents only" do
result = @repository.find(
result = @repository.find_and_expand(
'grid5000'
)
expect(result['uid']).to eq('grid5000')
expect(result['sites']).to be_nil
end
it "should return the blob's content if the object is a blob" do
result = @repository.find(
result = @repository.find_and_expand(
'grid5000/sites/grenoble/clusters/dahu/nodes/dahu-1'
)
expect(result['uid']).to eq('dahu-1')
end
# Hack to test symlink. Here srv-3 is a link to srv-2
it 'should correctly expand a symlink' do
result = @repository.find(
result = @repository.find_and_expand(
'grid5000/sites/nancy/servers/grcinq-srv-3.json'
)
expect(result).not_to be_nil
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment