Added doctrine L2 cache

in order to improve query performance
added L2 cache configuration to some
queries and classes.
also updated doctrine version.

Change-Id: I86ac24b65a28919de411b024c7ad175747630f6e
This commit is contained in:
Sebastian Marcet 2016-11-04 17:07:57 -03:00
parent dd9318a29b
commit 470dc12f5c
41 changed files with 5644 additions and 1010 deletions

3
.gitignore vendored
View File

@ -1,7 +1,6 @@
/vendor
/node_modules
composer.phar
composer.lock
.DS_Storeapp/storage
.idea/*
app/config/dev/*
@ -23,5 +22,5 @@ doc/build
*.egg-info
.env.testing
.env
storage/logs/*
storage/*
*.log

View File

@ -0,0 +1,54 @@
<?php namespace libs\utils;
/**
* Copyright 2016 OpenStack Foundation
* 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.
**/
use Doctrine\Common\Persistence\ManagerRegistry;
use Illuminate\Contracts\Container\Container;
use LaravelDoctrine\ORM\BootChain;
use LaravelDoctrine\ORM\DoctrineServiceProvider;
use LaravelDoctrine\ORM\IlluminateRegistry;
/**
* Class CustomDoctrineServiceProvider
* @package libs\utils
*/
final class CustomDoctrineServiceProvider extends DoctrineServiceProvider
{
/**
* Register the manager registry
*/
protected function registerManagerRegistry()
{
$this->app->singleton('registry', function ($app) {
$registry = new IlluminateRegistry($app, $app->make(CustomEntityManagerFactory::class));
// Add all managers into the registry
foreach ($app->make('config')->get('doctrine.managers', []) as $manager => $settings) {
$registry->addManager($manager, $settings);
}
return $registry;
});
// Once the registry get's resolved, we will call the resolve callbacks which were waiting for the registry
$this->app->afterResolving('registry', function (ManagerRegistry $registry, Container $container) {
$this->bootExtensionManager();
BootChain::boot($registry);
});
$this->app->alias('registry', ManagerRegistry::class);
$this->app->alias('registry', IlluminateRegistry::class);
}
}

View File

@ -0,0 +1,88 @@
<?php namespace libs\utils;
/**
* Copyright 2016 OpenStack Foundation
* 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.
**/
use Doctrine\ORM\Cache\DefaultCacheFactory;
use Doctrine\ORM\Cache\Logging\StatisticsCacheLogger;
use Doctrine\ORM\Cache\RegionsConfiguration;
use Doctrine\ORM\Configuration;
use LaravelDoctrine\ORM\EntityManagerFactory;
/**
* Class CustomEntityManagerFactory
* @package libs\utils
*/
final class CustomEntityManagerFactory extends EntityManagerFactory
{
/**
* @param Configuration $configuration
*/
protected function setSecondLevelCaching(Configuration $configuration)
{
$second_level_cache_config = $this->config->get('doctrine.cache.second_level', []);
if (!is_array($second_level_cache_config)) return;
if (!isset($second_level_cache_config['enabled'])) return;
if (!$second_level_cache_config['enabled']) return;
$configuration->setSecondLevelCacheEnabled(true);
$cacheConfig = $configuration->getSecondLevelCacheConfiguration();
$regions_config = isset($second_level_cache_config['regions']) ? $second_level_cache_config['regions'] : [];
if (is_array($regions_config) && count($regions_config) > 0) {
$regions_configuration = new RegionsConfiguration
(
isset($second_level_cache_config['region_lifetime']) ? $second_level_cache_config['region_lifetime'] : 3600,
isset($second_level_cache_config['region_lock_lifetime']) ? $second_level_cache_config['region_lock_lifetime'] : 60
);
foreach ($regions_config as $region_name => $region_config) {
if (isset($region_config['lifetime']))
$regions_configuration->setLifetime($region_name, $region_config['lifetime']);
if (isset($region_config['lock_lifetime']))
$regions_configuration->setLockLifetime($region_name, $region_config['lock_lifetime']);
}
$cacheConfig->setRegionsConfiguration($regions_configuration);
}
// Cache logger
if (isset($second_level_cache_config['log_enabled']) && $second_level_cache_config['log_enabled']){
$logger = new StatisticsCacheLogger();
$cacheConfig->setCacheLogger($logger);
}
$factory = new DefaultCacheFactory
(
$cacheConfig->getRegionsConfiguration(),
$this->cache->driver()
);
$file_lock_region_directory = isset($second_level_cache_config['file_lock_region_directory']) ?
$second_level_cache_config['file_lock_region_directory'] :
'/tmp';
$factory->setFileLockRegionDirectory($file_lock_region_directory);
$cacheConfig->setCacheFactory
(
$factory
);
}
}

View File

@ -14,8 +14,8 @@
use Closure;
use libs\utils\ICacheService;
use models\resource_server\IApiEndpoint;
use models\resource_server\IApiEndpointRepository;
use App\Models\ResourceServer\IApiEndpoint;
use App\Models\ResourceServer\IApiEndpointRepository;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Illuminate\Support\Facades\Cache;
@ -23,7 +23,6 @@ use Carbon\Carbon;
use Illuminate\Support\Facades\Config;
use libs\utils\RequestUtils;
/**
*
* @package App\Http\Middleware\
@ -90,6 +89,11 @@ class CORSMiddleware
*/
private $cache_service;
/**
* CORSMiddleware constructor.
* @param IApiEndpointRepository $endpoint_repository
* @param ICacheService $cache_service
*/
public function __construct(IApiEndpointRepository $endpoint_repository, ICacheService $cache_service)
{
$this->endpoint_repository = $endpoint_repository;
@ -130,6 +134,7 @@ class CORSMiddleware
public function preProcess(Request $request)
{
$actual_request = false;
if ($this->isValidCORSRequest($request))
{
if (!$this->testOriginHeaderScrutiny($request))
@ -159,7 +164,7 @@ class CORSMiddleware
return $response;
}
// ----Step 2b: Store pre-flight request data in the Cache to keep (mark) the request as correctly followed the request pre-flight process
$data = new CORSRequestPreflightData($request, $this->current_endpoint->supportCredentials());
$data = new CORSRequestPreflightData($request, $this->current_endpoint->isAllowCredentials());
$cache_id = $this->generatePreflightCacheKey($request);
$this->cache_service->storeHash($cache_id, $data->toArray(), CORSRequestPreflightData::$cache_lifetime);
// ----Step 2c: Return corresponding response - This part should be customized with application specific constraints.....
@ -186,7 +191,7 @@ class CORSMiddleware
if ($request->getMethod() === $data['expected_method'])
{
// ------Finish with custom HTTP headers (use an method to avoid manual iteration on collection to increase the speed)...
$x_headers = self::getCustomHeaders($request);
$x_headers = self::getCustomHeaders($request);
$x_headers_pre = explode(',', $data['expected_custom_headers']);
sort($x_headers);
sort($x_headers_pre);
@ -292,7 +297,7 @@ class CORSMiddleware
// The Access-Control-Allow-Credentials header indicates whether the response to request
// can be exposed when the omit credentials flag is unset. When part of the response to a preflight request
// it indicates that the actual request can include user credentials.
if ( $this->current_endpoint->supportCredentials())
if ( $this->current_endpoint->isAllowCredentials())
{
$response->headers->set('Access-Control-Allow-Credentials', 'true');
}
@ -433,7 +438,7 @@ class CORSMiddleware
{
return false;
}
if (!$this->current_endpoint->supportCORS() || !$this->current_endpoint->isActive())
if (!$this->current_endpoint->isAllowCors() || !$this->current_endpoint->isActive())
{
return false;
}

View File

@ -25,8 +25,8 @@ use libs\oauth2\OAuth2ResourceServerException;
use libs\oauth2\OAuth2WWWAuthenticateErrorResponse;
use libs\utils\RequestUtils;
use models\oauth2\IResourceServerContext;
use models\resource_server\IAccessTokenService;
use models\resource_server\IApiEndpointRepository;
use App\Models\ResourceServer\IAccessTokenService;
use App\Models\ResourceServer\IApiEndpointRepository;
use URL\Normalizer;
/**
@ -67,10 +67,10 @@ class OAuth2BearerAccessTokenRequestValidator
IApiEndpointRepository $endpoint_repository,
IAccessTokenService $token_service
) {
$this->context = $context;
$this->headers = $this->getHeaders();
$this->context = $context;
$this->headers = $this->getHeaders();
$this->endpoint_repository = $endpoint_repository;
$this->token_service = $token_service;
$this->token_service = $token_service;
}
/**
@ -152,7 +152,7 @@ class OAuth2BearerAccessTokenRequestValidator
throw new OAuth2ResourceServerException(
403,
OAuth2Protocol::OAuth2Protocol_Error_UnauthorizedClient,
sprintf('invalid origin %s - allowed ones (%s)',$origin, $token_info->getAllowedOrigins())
sprintf('invalid origin %s - allowed ones (%s)', $origin, $token_info->getAllowedOrigins())
);
}
//check scopes

View File

@ -17,7 +17,7 @@ use Closure;
use Illuminate\Support\Facades\Response;
use libs\utils\ICacheService;
use libs\utils\RequestUtils;
use models\resource_server\IApiEndpointRepository;
use App\Models\ResourceServer\IApiEndpointRepository;
/**
* Class RateLimitMiddleware
@ -63,11 +63,11 @@ final class RateLimitMiddleware
$url = $request->getRequestUri();
try {
$route = RequestUtils::getCurrentRoutePath($request);
$method = $request->getMethod();
$route = RequestUtils::getCurrentRoutePath($request);
$method = $request->getMethod();
$endpoint = $this->endpoint_repository->getApiEndpointByUrlAndMethod($route, $method);
if (!is_null($endpoint->rate_limit) && ($requestsPerHour = (int)$endpoint->rate_limit) > 0) {
if (!is_null($endpoint->getRateLimit()) && ($requestsPerHour = (int)$endpoint->getRateLimit()) > 0) {
//do rate limit checking
$key = sprintf('rate.limit.%s_%s_%s', $url, $method, $request->getClientIp());
// Add if doesn't exist

View File

@ -1,17 +1,17 @@
<?php namespace ModelSerializers;
/**
* Copyright 2016 OpenStack Foundation
* 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.
**/
* Copyright 2016 OpenStack Foundation
* 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.
**/
use libs\utils\JsonUtils;
@ -23,8 +23,8 @@ final class SummitEventFeedbackSerializer extends SilverStripeSerializer
{
protected static $array_mappings = array
(
'Rate' => 'rate:json_int',
'Note' => 'note:json_string',
'Rate' => 'rate:json_int',
'Note' => 'note:json_string',
'Created' => 'created_date:datetime_epoch',
'EventId' => 'event_id:json_int',
);
@ -39,14 +39,11 @@ final class SummitEventFeedbackSerializer extends SilverStripeSerializer
public function serialize($expand = null, array $fields = array(), array $relations = array(), array $params = array())
{
$feedback = $this->object;
$values = parent::serialize($expand, $fields, $relations, $params);
$event = $feedback->getEvent();
$member = $feedback->hasOwner() ? $feedback->getOwner() : null;
$values = parent::serialize($expand, $fields, $relations, $params);
$member = $feedback->hasOwner() ? $feedback->getOwner() : null;
if (is_null($member)) return $values;
$summit = $event->getSummit();
$attendee = $summit->getAttendeeByMemberId($member->getId());
if (!empty($expand)) {
foreach (explode(',', $expand) as $relation) {
@ -55,24 +52,20 @@ final class SummitEventFeedbackSerializer extends SilverStripeSerializer
$owner = array
(
'id' => intval($member->getId()),
'id' => intval($member->getId()),
'first_name' => JsonUtils::toJsonString($member->getFirstName()),
'last_name' => JsonUtils::toJsonString($member->getLastName())
'last_name' => JsonUtils::toJsonString($member->getLastName())
);
if (!is_null($attendee))
$owner['attendee_id'] = intval($attendee->getId());
$values['owner'] = $owner;
}
break;
break;
}
}
}
if(!isset($values['owner'])) {
if (!isset($values['owner'])) {
$values['member_id'] = intval($member->getId());
if (!is_null($attendee)) $values['attendee_id'] = intval($attendee->getId());
}
return $values;

View File

@ -19,6 +19,7 @@ use models\utils\SilverstripeBaseModel;
/**
* @ORM\Entity
* @ORM\Table(name="Company")
* @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="sponsors_region")
* Class Company
* @package models\main
*/

View File

@ -23,6 +23,7 @@ use Doctrine\Common\Collections\ArrayCollection;
* @ORM\Entity
* @ORM\Table(name="PresentationSpeaker")
* @ORM\Entity(repositoryClass="repositories\summit\DoctrineSpeakerRepository")
* @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="speakers_region")
* Class PresentationSpeaker
* @package models\summit
*/

View File

@ -551,6 +551,7 @@ class SummitEvent extends SilverstripeBaseModel
/**
* @ORM\OneToMany(targetEntity="models\summit\SummitEventFeedback", mappedBy="event", cascade={"persist"})
* @ORM\Cache("NONSTRICT_READ_WRITE")
* @var SummitEventFeedback[]
*/
protected $feedback;

View File

@ -21,6 +21,7 @@ use models\main\Member;
* @ORM\Entity
* @ORM\Table(name="SummitEventFeedback")
* @ORM\Entity(repositoryClass="repositories\summit\DoctrineEventFeedbackRepository")
* @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="summit_event_feedback_region")
* Class SummitEventFeedback
* @package models\summit
*/

View File

@ -12,12 +12,12 @@
* limitations under the License.
**/
use Doctrine\Common\Collections\Criteria;
use Doctrine\ORM\Query\ResultSetMappingBuilder;
use Doctrine\ORM\Cache;
use models\main\File;
use models\main\Member;
use models\utils\SilverstripeBaseModel;
use Doctrine\ORM\Mapping AS ORM;
use Doctrine\Common\Collections\Criteria;
use Doctrine\Common\Collections\ArrayCollection;
use DateTimeZone;
use DateTime;
@ -27,6 +27,7 @@ use models\main\Company;
* @ORM\Entity
* @ORM\Table(name="Summit")
* @ORM\Entity(repositoryClass="repositories\summit\DoctrineSummitRepository")
* @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="summit_region")
* Class Summit
* @package models\summit
*/
@ -678,6 +679,9 @@ class Summit extends SilverstripeBaseModel
->from('models\summit\PresentationSpeaker','ps')
->join('ps.moderated_presentations','p')
->join('p.summit','s')
->setCacheable(true)
->setCacheRegion('speakers_region')
->setCacheMode(Cache::MODE_NORMAL)
->where("s.id = :summit_id and p.published = 1")
->setParameter('summit_id', $this->getId());
}
@ -691,6 +695,9 @@ class Summit extends SilverstripeBaseModel
->from('models\summit\PresentationSpeaker','ps')
->join('ps.presentations','p')
->join('p.summit','s')
->setCacheable(true)
->setCacheRegion('speakers_region')
->setCacheMode(Cache::MODE_NORMAL)
->where("s.id = :summit_id and p.published = 1")
->setParameter('summit_id', $this->getId());
}
@ -788,6 +795,9 @@ class Summit extends SilverstripeBaseModel
->from('models\main\Company','c')
->join('c.sponsorships','sp')
->join('sp.summit','s')
->setCacheable(true)
->setCacheRegion('sponsors_region')
->setCacheMode(Cache::MODE_NORMAL)
->where('s.id = :summit_id and sp.published = 1')
->setParameter('summit_id', $this->getId())->getQuery()->getResult();
}

View File

@ -1,4 +1,4 @@
<?php namespace models\resource_server;
<?php namespace App\Models\ResourceServer;
/**
* Copyright 2015 OpenStack Foundation
@ -26,7 +26,7 @@ use Illuminate\Support\Facades\Log;
/**
* Class AccessTokenService
* @package models\resource_server
* @package App\Models\ResourceServer
*/
final class AccessTokenService implements IAccessTokenService
{
@ -141,7 +141,7 @@ final class AccessTokenService implements IAccessTokenService
private function doIntrospection($token_value){
Log::debug("getting token from remote call ...");
$cache_lifetime = intval(Config::get('server.access_token_cache_lifetime', 300));
$token_info = $this->makeRemoteCall($token_value);
$token_info = $this->doIntrospectionRequest($token_value);
$this->cache_service->storeHash(md5($token_value), $token_info, $cache_lifetime );
return $token_info;
}
@ -154,7 +154,7 @@ final class AccessTokenService implements IAccessTokenService
* @throws OAuth2InvalidIntrospectionResponse
* @throws \Exception
*/
private function makeRemoteCall($token_value)
private function doIntrospectionRequest($token_value)
{
try {
@ -185,7 +185,7 @@ final class AccessTokenService implements IAccessTokenService
$response = $client->post(
$auth_server_url . '/oauth2/token/introspection',
[
'query' => ['token' => $token_value],
'body' => ['token' => $token_value],
'headers' => ['Authorization' => " Basic " . base64_encode($client_id . ':' . $client_secret)]
]
);

View File

@ -1,4 +1,4 @@
<?php namespace models\resource_server;
<?php namespace App\Models\ResourceServer;
/**
* Copyright 2015 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
@ -12,50 +12,136 @@
* limitations under the License.
**/
use models\utils\BaseModelEloquent;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping AS ORM;
/**
* Class Api
* @package models\resource_server
* @ORM\Entity
* @ORM\Table(name="apis")
* @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="resource_server_region")
* Class Api
* @package App\Models\ResourceServer
*/
class Api extends BaseModelEloquent implements IApi
class Api extends ResourceServerEntity implements IApi
{
protected $table = 'apis';
/**
* @ORM\OneToMany(targetEntity="ApiScope", mappedBy="api", cascade={"persist"})
*/
private $scopes;
protected $fillable = array('name','description','active');
/**
* @ORM\OneToMany(targetEntity="ApiEndpoint", mappedBy="api", cascade={"persist"})
*/
private $endpoints;
/**
* @ORM\Column(name="name", type="string")
* @var string
*/
private $name;
/**
* @return IApiScope[]
*/
public function scopes()
{
return $this->hasMany('models\resource_server\ApiScope', 'api_id');
}
/**
* @ORM\Column(name="description", type="string")
* @var string
*/
private $description;
/**
* @return IApiEndpoint[]
*/
public function endpoints()
{
return $this->hasMany('models\resource_server\ApiEndpoint', 'api_id');
}
/**
* @ORM\Column(name="active", type="boolean")
* @var bool
*/
private $active;
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* Api constructor.
*/
public function __construct()
{
parent::__construct();
$this->scopes = new ArrayCollection();
$this->endpoints = new ArrayCollection();
}
/**
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* @return ApiScope[]
*/
public function getScopes()
{
return $this->scopes;
}
/**
* @param mixed $scopes
*/
public function setScopes($scopes)
{
$this->scopes = $scopes;
}
/**
* @return ApiEndpoint[]
*/
public function getEndpoints()
{
return $this->endpoints;
}
/**
* @param mixed $endpoints
*/
public function setEndpoints($endpoints)
{
$this->endpoints = $endpoints;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param string $name
*/
public function setName($name)
{
$this->name = $name;
}
/**
* @return string
*/
public function getDescription()
{
return $this->description;
}
/**
* @param string $description
*/
public function setDescription($description)
{
$this->description = $description;
}
/**
* @return boolean
*/
public function isActive()
{
return $this->active;
}
/**
* @param boolean $active
*/
public function setActive($active)
{
$this->active = $active;
}
/**
* @return string
@ -63,38 +149,16 @@ class Api extends BaseModelEloquent implements IApi
public function getScope()
{
$scope = '';
foreach ($this->scopes()->get() as $s)
foreach ($this->getScopes() as $s)
{
if (!$s->active)
if (!$s->isActive())
{
continue;
}
$scope = $scope .$s->name.' ';
$scope = $scope .$s->getName().' ';
}
$scope = trim($scope);
return $scope;
}
/**
* @return bool
*/
public function isActive()
{
return $this->active;
}
public function setName($name)
{
$this->name = $name;
}
public function setDescription($description)
{
$this->description = $description;
}
public function setStatus($active)
{
$this->active = $active;
}
}

View File

@ -1,4 +1,4 @@
<?php namespace models\resource_server;
<?php namespace App\Models\ResourceServer;
/**
* Copyright 2015 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
@ -12,132 +12,276 @@
* limitations under the License.
**/
use models\utils\BaseModelEloquent;
use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping AS ORM;
/**
* Class ApiEndpoint
* @package models\resource_server
* @ORM\Entity(repositoryClass="repositories\resource_server\DoctrineApiEndpointRepository")
* @ORM\Table(name="api_endpoints")
* @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="resource_server_region")
* Class ApiEndpoint
* @package App\Models\ResourceServer
*/
class ApiEndpoint extends BaseModelEloquent implements IApiEndpoint
class ApiEndpoint extends ResourceServerEntity implements IApiEndpoint
{
protected $table = 'api_endpoints';
/**
* @return Api
*/
public function getApi()
{
return $this->api;
}
protected $fillable = array(
'description',
'active',
'allow_cors',
'allow_credentials',
'name','route',
'http_method',
'api_id',
'rate_limit'
);
/**
* @param Api $api
*/
public function setApi($api)
{
$this->api = $api;
}
/**
* @return IApi
*/
public function api()
{
return $this->belongsTo('models\resource_server\Api', 'api_id');
}
/**
* @return ApiScope[]
*/
public function getScopes()
{
return $this->scopes;
}
/**
* @return IApiScope[]
*/
public function scopes()
{
return $this->belongsToMany('models\resource_server\ApiScope', 'endpoint_api_scopes', 'api_endpoint_id', 'scope_id');
}
/**
* @param ApiScope[] $scopes
*/
public function setScopes($scopes)
{
$this->scopes = $scopes;
}
public function getRoute()
{
return $this->route;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
public function getHttpMethod()
{
return $this->http_method;
}
/**
* @param string $name
*/
public function setName($name)
{
$this->name = $name;
}
public function setRoute($route)
{
$this->route = $route;
}
/**
* @return string
*/
public function getDescription()
{
return $this->description;
}
public function setHttpMethod($http_method)
{
$this->http_method = $http_method;
}
/**
* @param string $description
*/
public function setDescription($description)
{
$this->description = $description;
}
/**
/**
* @return boolean
*/
public function isActive()
{
return $this->active;
}
/**
* @param boolean $active
*/
public function setActive($active)
{
$this->active = $active;
}
/**
* @return boolean
*/
public function isAllowCors()
{
return $this->allow_cors;
}
/**
* @param boolean $allow_cors
*/
public function setAllowCors($allow_cors)
{
$this->allow_cors = $allow_cors;
}
/**
* @return boolean
*/
public function isAllowCredentials()
{
return $this->allow_credentials;
}
/**
* @param boolean $allow_credentials
*/
public function setAllowCredentials($allow_credentials)
{
$this->allow_credentials = $allow_credentials;
}
/**
* @return string
*/
public function getRoute()
{
return $this->route;
}
/**
* @param string $route
*/
public function setRoute($route)
{
$this->route = $route;
}
/**
* @return string
*/
public function getHttpMethod()
{
return $this->http_method;
}
/**
* @param string $http_method
*/
public function setHttpMethod($http_method)
{
$this->http_method = $http_method;
}
/**
* @ORM\ManyToOne(targetEntity="Api", cascade={"persist"})
* @ORM\JoinColumn(name="api_id", referencedColumnName="id")
* @var Api
*/
private $api;
/**
* @ORM\ManyToMany(targetEntity="ApiScope")
* @ORM\JoinTable(name="endpoint_api_scopes",
* joinColumns={@ORM\JoinColumn(name="api_endpoint_id", referencedColumnName="id")},
* inverseJoinColumns={@ORM\JoinColumn(name="scope_id", referencedColumnName="id")}
* )
* @var ApiScope[]
*/
private $scopes;
/**
* @ORM\Column(name="name", type="string")
* @var string
*/
private $name;
/**
* @ORM\Column(name="description", type="string")
* @var string
*/
private $description;
/**
* @ORM\Column(name="active", type="boolean")
* @var bool
*/
private $active;
/**
* @ORM\Column(name="allow_cors", type="boolean")
* @var bool
*/
private $allow_cors;
/**
* @ORM\Column(name="allow_credentials", type="boolean")
* @var bool
*/
private $allow_credentials;
/**
* @ORM\Column(name="route", type="string")
* @var string
*/
private $route;
/**
* @ORM\Column(name="http_method", type="string")
* @var string
*/
private $http_method;
/**
* @ORM\Column(name="rate_limit", type="integer")
* @var int
*/
private $rate_limit;
/**
* ApiEndpoint constructor.
*/
public function __construct()
{
parent::__construct();
$this->rate_limit = 0;
$this->scopes = new ArrayCollection();
}
/**
* @return string
*/
public function getScope()
{
$scope = '';
foreach ($this->scopes()->get() as $s)
foreach ($this->scopes as $s)
{
if (!$s->active)
if (!$s->isActive())
{
continue;
}
$scope = $scope .$s->name.' ';
$scope = $scope .$s->getName().' ';
}
$scope = trim($scope);
return $scope;
}
public function isActive()
{
return $this->active;
}
/**
* @param IApiScope $scope
*/
public function addScope(IApiScope $scope){
$this->scopes->add($scope);
}
/**
* @param bool $active
*/
public function setStatus($active)
{
$this->active = $active;
}
/**
* @return int
*/
public function getRateLimit()
{
return $this->rate_limit;
}
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @param int $rate_limit
*/
public function setRateLimit($rate_limit)
{
$this->rate_limit = $rate_limit;
}
/**
* @param string $name
*/
public function setName($name)
{
$this->name= $name;
}
/**
* @return bool
*/
public function supportCORS()
{
return $this->allow_cors;
}
/**
* @return bool
*/
public function supportCredentials()
{
return (bool)$this->allow_credentials;
}
/**
* @return int
*/
public function getIdentifier()
{
return (int)$this->id;
}
}

View File

@ -1,4 +1,4 @@
<?php namespace models\resource_server;
<?php namespace App\Models\ResourceServer;
/**
* Copyright 2015 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
@ -12,46 +12,147 @@
* limitations under the License.
**/
use models\utils\BaseModelEloquent;
use Doctrine\ORM\Mapping AS ORM;
/**
* Class ApiScope
* @package models\resource_server
*/
class ApiScope extends BaseModelEloquent implements IApiScope
* @ORM\Entity
* @ORM\Table(name="api_scopes")
* @ORM\Cache(usage="NONSTRICT_READ_WRITE", region="resource_server_region")
* Class ApiScope
* @package App\Models\ResourceServer
*/
class ApiScope extends ResourceServerEntity implements IApiScope
{
/**
* @return IApi
*/
public function getApi()
{
return $this->api;
}
protected $table = 'api_scopes';
/**
* @param Api $api
*/
public function setApi(Api $api)
{
$this->api = $api;
}
protected $hidden = array('');
/**
* @ORM\ManyToOne(targetEntity="Api", cascade={"persist"})
* @ORM\JoinColumn(name="api_id", referencedColumnName="id")
* @var Api
*/
private $api;
protected $fillable = array('name' ,'short_description', 'description','active','default','system', 'api_id');
/**
* @return string
*/
public function getName()
{
return $this->name;
}
/**
* @return IApi
*/
public function api()
{
return $this->belongsTo('models\resource_server\Api', 'api_id');
}
/**
* @param string $name
*/
public function setName($name)
{
$this->name = $name;
}
public function getShortDescription()
{
return $this->short_description;
}
/**
* @return string
*/
public function getDescription()
{
return $this->description;
}
public function getName()
{
return $this->name;
}
/**
* @param string $description
*/
public function setDescription($description)
{
$this->description = $description;
}
public function getDescription()
{
return $this->description;
}
/**
* @return string
*/
public function getShortDescription()
{
return $this->short_description;
}
public function isActive()
{
return $this->active;
}
/**
* @param string $short_description
*/
public function setShortDescription($short_description)
{
$this->short_description = $short_description;
}
/**
* @return boolean
*/
public function isActive()
{
return $this->active;
}
/**
* @param boolean $active
*/
public function setActive($active)
{
$this->active = $active;
}
/**
* @ORM\Column(name="name", type="string")
* @var string
*/
private $name;
/**
* @ORM\Column(name="description", type="string")
* @var string
*/
private $description;
/**
* @return boolean
*/
public function isDefault()
{
return $this->default;
}
/**
* @param boolean $default
*/
public function setDefault($default)
{
$this->default = $default;
}
/**
* @ORM\Column(name="short_description", type="string")
* @var string
*/
private $short_description;
/**
* @ORM\Column(name="active", type="boolean")
* @var bool
*/
private $active;
/**
* @ORM\Column(name="`default`", type="boolean")
* @var bool
*/
private $default;
}

View File

@ -1,4 +1,4 @@
<?php namespace models\resource_server;
<?php namespace App\Models\ResourceServer;
/**
* Copyright 2015 OpenStack Foundation
@ -18,7 +18,7 @@ use models\oauth2\AccessToken;
/**
* Interface IAccessTokenService
* @package models\resource_server
* @package App\Models\ResourceServer
*/
interface IAccessTokenService
{

View File

@ -1,4 +1,4 @@
<?php namespace models\resource_server;
<?php namespace App\Models\ResourceServer;
/**
* Copyright 2015 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
@ -14,11 +14,10 @@
/**
* Interface IApi
* @package models\resource_server
* @package App\Models\ResourceServer
*/
interface IApi
{
/**
* @return string
*/
@ -55,16 +54,16 @@ interface IApi
* @param bool $active
* @return void
*/
public function setStatus($active);
public function setActive($active);
/**
* @return IApiEndpoint[]
*/
public function endpoints();
public function getEndpoints();
/**
* @return IApiScope[]
*/
public function scopes();
public function getScopes();
}

View File

@ -1,22 +1,22 @@
<?php namespace models\resource_server;
<?php namespace App\Models\ResourceServer;
/**
* Copyright 2015 OpenStack Foundation
* 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.
**/
/**
* Copyright 2015 OpenStack Foundation
* 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.
**/
use models\utils\IEntity;
/**
* Interface IApiEndpoint
* @package models\resource_server
* @package App\Models\ResourceServer
*/
interface IApiEndpoint extends IEntity
{
@ -68,26 +68,36 @@ interface IApiEndpoint extends IEntity
* @param bool $active
* @return void
*/
public function setStatus($active);
public function setActive($active);
/**
* @return bool
*/
public function supportCORS();
public function isAllowCors();
/**
* @return bool
*/
public function supportCredentials();
public function isAllowCredentials();
/**
* @return IApi
*/
public function api();
public function getApi();
/**
* @return IApiScope[]
*/
public function scopes();
public function getScopes();
/**
* @param IApiScope $scope
*/
public function addScope(IApiScope $scope);
/**
* @return int
*/
public function getRateLimit();
}

View File

@ -1,4 +1,4 @@
<?php namespace models\resource_server;
<?php namespace App\Models\ResourceServer;
/**
* Copyright 2015 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
@ -16,7 +16,7 @@ use models\utils\IBaseRepository;
/**
* Interface IApiEndpointRepository
* @package models\resource_server
* @package App\Models\ResourceServer
*/
interface IApiEndpointRepository extends IBaseRepository
{

View File

@ -1,4 +1,4 @@
<?php namespace models\resource_server;
<?php namespace App\Models\ResourceServer;
/**
* Copyright 2015 OpenStack Foundation
* Licensed under the Apache License, Version 2.0 (the "License");
@ -15,7 +15,7 @@
/**
* Interface IApiScope
* http://tools.ietf.org/html/rfc6749#section-3.3
* @package oauth2\models
* @package App\Models\ResourceServer
*/
interface IApiScope
{
@ -39,8 +39,8 @@ interface IApiScope
*/
public function isActive();
/**
* @return IApi
*/
public function api();
/**
* @return IApi
*/
public function getApi();
}

View File

@ -0,0 +1,96 @@
<?php namespace App\Models\ResourceServer;
/**
* Copyright 2016 OpenStack Foundation
* 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.
**/
use models\utils\IEntity;
use Doctrine\ORM\Mapping AS ORM;
/***
* @ORM\MappedSuperclass
* Class ResourceServerEntity
* @package App\Models\ResourceServer
*/
class ResourceServerEntity implements IEntity
{
const DefaultTimeZone = 'America/Chicago';
/**
* @ORM\Id
* @ORM\GeneratedValue
* @ORM\Column(name="id", type="integer", unique=true, nullable=false)
*/
protected $id;
/**
* @ORM\Column(name="created_at", type="datetime")
*/
protected $created;
/**
* @ORM\Column(name="updated_at", type="datetime")
*/
protected $last_edited;
/**
* @return int
*/
public function getIdentifier()
{
return (int)$this->id;
}
public function getId(){
return $this->getIdentifier();
}
/**
* @return \DateTime
*/
public function getCreated()
{
return $this->created;
}
/**
* @param \DateTime $created
*/
public function setCreated($created)
{
$this->created = $created;
}
/**
* @return \DateTime
*/
public function getLastEdited()
{
return $this->last_edited;
}
/**
* @param \DateTime $last_edited
*/
public function setLastEdited($last_edited)
{
$this->last_edited = $last_edited;
}
public function __construct()
{
$now = new \DateTime('now', new \DateTimeZone(self::DefaultTimeZone));
$this->created = $now;
$this->last_edited = $now;
}
}

View File

@ -14,10 +14,10 @@
use Doctrine\ORM\EntityManager;
use Doctrine\ORM\Mapping AS ORM;
use Doctrine\ORM\NativeQuery;
use Doctrine\ORM\Query;
use Doctrine\ORM\QueryBuilder;
use Registry;
/***
* @ORM\MappedSuperclass
* Class SilverstripeBaseModel
@ -26,8 +26,9 @@ use Registry;
class SilverstripeBaseModel implements IEntity
{
const DefaultTimeZone = 'America/Chicago';
/**
* @return mixed
* @return \DateTime
*/
public function getCreated()
{
@ -35,7 +36,7 @@ class SilverstripeBaseModel implements IEntity
}
/**
* @param mixed $created
* @param \DateTime $created
*/
public function setCreated($created)
{
@ -43,7 +44,7 @@ class SilverstripeBaseModel implements IEntity
}
/**
* @return mixed
* @return \DateTime
*/
public function getLastEdited()
{
@ -51,7 +52,7 @@ class SilverstripeBaseModel implements IEntity
}
/**
* @param mixed $last_edited
* @param \DateTime $last_edited
*/
public function setLastEdited($last_edited)
{

View File

@ -105,9 +105,9 @@ class AppServiceProvider extends ServiceProvider
public function register()
{
App::singleton('models\\oauth2\\IResourceServerContext', 'models\\oauth2\\ResourceServerContext');
App::singleton('models\resource_server\\IAccessTokenService', 'models\resource_server\\AccessTokenService');
App::singleton('models\\resource_server\\IApi', 'models\\resource_server\\Api');
App::singleton('models\\resource_server\\IApiEndpoint', 'models\\resource_server\\ApiEndpoint');
App::singleton('models\\resource_server\\IApiScope', 'models\\resource_server\\ApiScope');
App::singleton('App\Models\ResourceServer\IAccessTokenService', 'App\Models\ResourceServer\AccessTokenService');
App::singleton('App\Models\ResourceServer\IApi', 'models\\resource_server\\Api');
App::singleton('App\Models\ResourceServer\IApiEndpoint', 'models\\resource_server\\ApiEndpoint');
App::singleton('App\Models\ResourceServer\IApiScope', 'models\\resource_server\\ApiScope');
}
}

View File

@ -44,10 +44,12 @@ class RepositoriesProvider extends ServiceProvider
'models\marketplace\IConsultantRepository',
'repositories\marketplace\EloquentConsultantRepository'
);
App::singleton(
'models\resource_server\IApiEndpointRepository',
'repositories\resource_server\EloquentApiEndpointRepository'
);
'App\Models\ResourceServer\IApiEndpointRepository',
function(){
return EntityManager::getRepository(\App\Models\ResourceServer\ApiEndpoint::class);
});
App::singleton(
'models\summit\ISummitRepository',
@ -80,7 +82,6 @@ class RepositoriesProvider extends ServiceProvider
});
App::singleton(
'models\main\IMemberRepository',
function(){

View File

@ -0,0 +1,52 @@
<?php namespace repositories\resource_server;
/**
* Copyright 2016 OpenStack Foundation
* 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.
**/
use App\Models\ResourceServer\IApiEndpoint;
use App\Models\ResourceServer\IApiEndpointRepository;
use repositories\DoctrineRepository;
use Illuminate\Support\Facades\Log;
/**
* Class DoctrineApiEndpointRepository
* @package repositories\resource_server
*/
final class DoctrineApiEndpointRepository extends DoctrineRepository implements IApiEndpointRepository
{
/**
* @param string $url
* @param string $http_method
* @return IApiEndpoint
*/
public function getApiEndpointByUrlAndMethod($url, $http_method)
{
try {
return $this->getEntityManager()->createQueryBuilder()
->select("e")
->from(\App\Models\ResourceServer\ApiEndpoint::class, "e")
->where('e.route = :route')
->andWhere('e.http_method = :http_method')
->setParameter('route', trim($url))
->setParameter('http_method', trim($http_method))
->setCacheable(true)
->setCacheRegion('resource_server_region')
->getQuery()
->getOneOrNullResult();
}
catch(\Exception $ex){
Log::error($ex);
return null;
}
}
}

View File

@ -13,10 +13,9 @@
* limitations under the License.
**/
use models\resource_server\IApiEndpoint;
use models\resource_server\IApiEndpointRepository;
use App\Models\ResourceServer\IApiEndpoint;
use App\Models\ResourceServer\IApiEndpointRepository;
use models\utils\EloquentBaseRepository;
use models\utils\IEntity;
/**
* Class EloquentApiEndpointRepository

View File

@ -12,6 +12,7 @@
* limitations under the License.
**/
use Doctrine\ORM\Cache;
use models\summit\IEventFeedbackRepository;
use repositories\SilverStripeDoctrineRepository;
use models\summit\SummitEvent;
@ -38,13 +39,16 @@ final class DoctrineEventFeedbackRepository extends SilverStripeDoctrineReposito
*/
public function getByEvent(SummitEvent $event, PagingInfo $paging_info, Filter $filter = null, Order $order = null)
{
$query = $this->getEntityManager()->createQueryBuilder()
->select("f")
->from(\models\summit\SummitEventFeedback::class, "f")
->join('f.event', 'e', Join::WITH, " e.id = :event_id")
->join('f.owner', 'o')
->setParameter('event_id', $event->getId());
$query = $this->getEntityManager()
->createQueryBuilder()
->select("f")
->from(\models\summit\SummitEventFeedback::class, "f")
->join('f.event', 'e', Join::WITH, " e.id = :event_id")
->join('f.owner', 'o')
->setParameter('event_id', $event->getId())
->setCacheable(true)
->setCacheMode(Cache::MODE_GET)
->setCacheRegion('summit_event_feedback_region');
if(!is_null($filter)){

View File

@ -14,8 +14,8 @@
"guzzlehttp/guzzle": "5.3.0",
"ezyang/htmlpurifier": "4.7.0",
"glenscott/url-normalizer" : "^1.4",
"laravel-doctrine/orm":"1.1.*",
"laravel-doctrine/extensions": "^1.0",
"laravel-doctrine/orm":"1.2.*",
"laravel-doctrine/extensions": "1.0.*",
"cocur/slugify": "^2.3"
},
"require-dev": {

4346
composer.lock generated Normal file

File diff suppressed because it is too large Load Diff

View File

@ -162,7 +162,7 @@ return [
\repositories\RepositoriesProvider::class,
\services\ServicesProvider::class,
\factories\FactoriesProvider::class,
\LaravelDoctrine\ORM\DoctrineServiceProvider::class,
\libs\utils\CustomDoctrineServiceProvider::class,
\LaravelDoctrine\Extensions\BeberleiExtensionsServiceProvider::class,
],

View File

@ -213,7 +213,20 @@ return [
'cache' => [
'default' => env('DOCTRINE_CACHE', 'redis'),
'namespace' => null,
'second_level' => true,
'second_level' => [
'enabled' => true,
'region_lifetime' => 3600,
'region_lock_lifetime' => 60,
'regions' => [
'summit_event_feedback_region' => [
'lifetime' => 300,
'lock_lifetime' => 60
]
],
'log_enabled' => true,
'file_lock_region_directory' => '/tmp'
]
],
/*
|--------------------------------------------------------------------------

View File

@ -14,9 +14,8 @@
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Config;
use models\resource_server\Api;
use models\resource_server\ApiEndpoint;
use models\resource_server\ApiScope;
use App\Models\ResourceServer\ApiEndpoint;
use LaravelDoctrine\ORM\Facades\EntityManager;
/**
* Class ApiEndpointsSeeder
@ -34,762 +33,417 @@ class ApiEndpointsSeeder extends Seeder
$this->seedSummitEndpoints();
}
/**
* @param string $api_name
* @param array $endpoints_info
*/
private function seedApiEndpoints($api_name, array $endpoints_info){
$api = EntityManager::getRepository(\App\Models\ResourceServer\Api::class)->findOneBy(['name' => $api_name]);
if(is_null($api)) return;
foreach($endpoints_info as $endpoint_info){
$endpoint = new ApiEndpoint();
$endpoint->setName($endpoint_info['name']);
$endpoint->setRoute($endpoint_info['route']);
$endpoint->setHttpMethod($endpoint_info['http_method']);
$endpoint->setActive(true);
$endpoint->setAllowCors(true);
$endpoint->setAllowCredentials(true);
$endpoint->setApi($api);
foreach($endpoint_info['scopes'] as $scope_name){
$scope = EntityManager::getRepository(\App\Models\ResourceServer\ApiScope::class)->findOneBy(['name' => $scope_name]);
if(is_null($scope)) continue;
$endpoint->addScope($scope);
}
EntityManager::persist($endpoint);
}
EntityManager::flush();
}
private function seedPublicCloudsEndpoints()
{
$public_clouds = Api::where('name', '=', 'public-clouds')->first();
$current_realm = Config::get('app.url');
// endpoints scopes
ApiEndpoint::create(
$this->seedApiEndpoints('public-clouds', [
array(
'name' => 'get-public-clouds',
'active' => true,
'api_id' => $public_clouds->id,
'route' => '/api/v1/marketplace/public-clouds',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [
sprintf('%s/public-clouds/read', $current_realm),
],
),
array(
'name' => 'get-public-cloud',
'active' => true,
'api_id' => $public_clouds->id,
'route' => '/api/v1/marketplace/public-clouds/{id}',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [
sprintf('%s/public-clouds/read', $current_realm),
],
),
array(
'name' => 'get-public-cloud-datacenters',
'active' => true,
'api_id' => $public_clouds->id,
'route' => '/api/v1/marketplace/public-clouds/{id}/data-centers',
'http_method' => 'GET'
'http_method' => 'GET',
'scopes' => [
sprintf('%s/public-clouds/read', $current_realm),
],
)
);
$public_cloud_read_scope = ApiScope::where('name', '=',
sprintf('%s/public-clouds/read', $current_realm))->first();
$endpoint_get_public_clouds = ApiEndpoint::where('name', '=', 'get-public-clouds')->first();
$endpoint_get_public_clouds->scopes()->attach($public_cloud_read_scope->id);
$endpoint_get_public_cloud = ApiEndpoint::where('name', '=', 'get-public-cloud')->first();
$endpoint_get_public_cloud->scopes()->attach($public_cloud_read_scope->id);
$endpoint_get_public_cloud_datacenters = ApiEndpoint::where('name', '=',
'get-public-cloud-datacenters')->first();
$endpoint_get_public_cloud_datacenters->scopes()->attach($public_cloud_read_scope->id);
]);
}
private function seedPrivateCloudsEndpoints()
{
$private_clouds = Api::where('name', '=', 'private-clouds')->first();
$current_realm = Config::get('app.url');
// endpoints scopes
ApiEndpoint::create(
$this->seedApiEndpoints('private-clouds', [
array(
'name' => 'get-private-clouds',
'active' => true,
'api_id' => $private_clouds->id,
'route' => '/api/v1/marketplace/private-clouds',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [sprintf('%s/private-clouds/read', $current_realm)],
),
array(
'name' => 'get-private-cloud',
'active' => true,
'api_id' => $private_clouds->id,
'route' => '/api/v1/marketplace/private-clouds/{id}',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [sprintf('%s/private-clouds/read', $current_realm)],
),
array(
'name' => 'get-private-cloud-datacenters',
'active' => true,
'api_id' => $private_clouds->id,
'route' => '/api/v1/marketplace/private-clouds/{id}/data-centers',
'http_method' => 'GET'
'http_method' => 'GET',
'scopes' => [sprintf('%s/private-clouds/read', $current_realm)],
)
);
$private_cloud_read_scope = ApiScope::where('name', '=',
sprintf('%s/private-clouds/read', $current_realm))->first();
$endpoint_get_private_clouds = ApiEndpoint::where('name', '=', 'get-private-clouds')->first();
$endpoint_get_private_clouds->scopes()->attach($private_cloud_read_scope->id);
$endpoint_get_private_cloud = ApiEndpoint::where('name', '=', 'get-private-cloud')->first();
$endpoint_get_private_cloud->scopes()->attach($private_cloud_read_scope->id);
$endpoint_get_private_cloud_datacenters = ApiEndpoint::where('name', '=',
'get-private-cloud-datacenters')->first();
$endpoint_get_private_cloud_datacenters->scopes()->attach($private_cloud_read_scope->id);
]);
}
private function seedConsultantsEndpoints()
{
$consultants = Api::where('name', '=', 'consultants')->first();
$current_realm = Config::get('app.url');
// endpoints scopes
ApiEndpoint::create(
$this->seedApiEndpoints('consultants', [
array(
'name' => 'get-consultants',
'active' => true,
'api_id' => $consultants->id,
'route' => '/api/v1/marketplace/consultants',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [sprintf('%s/consultants/read', $current_realm)],
),
array(
'name' => 'get-consultant',
'active' => true,
'api_id' => $consultants->id,
'route' => '/api/v1/marketplace/consultants/{id}',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [sprintf('%s/consultants/read', $current_realm)],
),
array(
'name' => 'get-consultant-offices',
'active' => true,
'api_id' => $consultants->id,
'route' => '/api/v1/marketplace/consultants/{id}/offices',
'http_method' => 'GET'
'http_method' => 'GET',
'scopes' => [sprintf('%s/consultants/read', $current_realm)],
)
);
$consultant_read_scope = ApiScope::where('name', '=', sprintf('%s/consultants/read', $current_realm))->first();
$endpoint = ApiEndpoint::where('name', '=', 'get-consultants')->first();
$endpoint->scopes()->attach($consultant_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-consultant')->first();
$endpoint->scopes()->attach($consultant_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-consultant-offices')->first();
$endpoint->scopes()->attach($consultant_read_scope->id);
]);
}
private function seedSummitEndpoints()
{
$summit = Api::where('name', '=', 'summits')->first();
$current_realm = Config::get('app.url');
// endpoints scopes
ApiEndpoint::create(
$this->seedApiEndpoints('summits', [
// summits
array(
'name' => 'get-summits',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [sprintf('%s/summits/read', $current_realm)],
),
array(
'name' => 'get-summit',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [sprintf('%s/summits/read', $current_realm)],
),
array(
'name' => 'get-summit-entity-events',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/entity-events',
'http_method' => 'GET'
)
);
// attendees
ApiEndpoint::create
(
'http_method' => 'GET',
'scopes' => [sprintf('%s/summits/read', $current_realm)],
),
// attendees
array(
'name' => 'get-attendees',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/attendees',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [sprintf('%s/summits/read', $current_realm)],
),
array(
'name' => 'get-attendee',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/attendees/{attendee_id}',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [sprintf('%s/summits/read', $current_realm)],
),
array(
'name' => 'get-attendee-schedule',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/attendees/{attendee_id}/schedule',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [sprintf('%s/summits/read', $current_realm)],
),
array(
'name' => 'add-event-attendee-schedule',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/attendees/{attendee_id}/schedule/{event_id}',
'http_method' => 'POST'
)
);
ApiEndpoint::create(
'http_method' => 'POST',
'scopes' => [sprintf('%s/summits/write', $current_realm)],
),
array(
'name' => 'delete-event-attendee-schedule',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/attendees/{attendee_id}/schedule/{event_id}',
'http_method' => 'DELETE'
)
);
ApiEndpoint::create(
'http_method' => 'DELETE',
'scopes' => [sprintf('%s/summits/write', $current_realm)],
),
array(
'name' => 'checking-event-attendee-schedule',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/attendees/{attendee_id}/schedule/{event_id}/check-in',
'http_method' => 'PUT'
)
);
// speakers
ApiEndpoint::create(
'http_method' => 'PUT',
'scopes' => [sprintf('%s/summits/write', $current_realm)],
),
// speakers
array(
'name' => 'get-speakers',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/speakers',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [sprintf('%s/summits/read', $current_realm)],
),
array(
'name' => 'get-speaker',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/speakers/{speaker_id}',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [sprintf('%s/summits/read', $current_realm)],
),
array(
'name' => 'add-speaker-feedback',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/speakers/{speaker_id}/presentations/{presentation_id}/feedback',
'http_method' => 'POST'
)
);
// events
ApiEndpoint::create(
'http_method' => 'POST',
'scopes' => [sprintf('%s/summits/write', $current_realm)],
),
// events
array(
'name' => 'get-events',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/events',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [sprintf('%s/summits/read', $current_realm)],
),
array(
'name' => 'get-published-events',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/events/published',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [sprintf('%s/summits/read', $current_realm)],
),
array(
'name' => 'get-all-events',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/events',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [sprintf('%s/summits/read', $current_realm)],
),
array(
'name' => 'get-all-published-events',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/events/published',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [sprintf('%s/summits/read', $current_realm)],
),
array(
'name' => 'get-event',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/events/{event_id}',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [sprintf('%s/summits/read', $current_realm)],
),
array(
'name' => 'get-published-event',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/events/{event_id}/published',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [sprintf('%s/summits/read', $current_realm)],
),
array(
'name' => 'add-event',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/events',
'http_method' => 'POST'
)
);
ApiEndpoint::create(
'http_method' => 'POST',
'scopes' => [sprintf('%s/summits/write-event', $current_realm)],
),
array(
'name' => 'update-event',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/events/{event_id}',
'http_method' => 'PUT'
)
);
ApiEndpoint::create(
'http_method' => 'PUT',
'scopes' => [sprintf('%s/summits/write-event', $current_realm)],
),
array(
'name' => 'publish-event',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/events/{event_id}/publish',
'http_method' => 'PUT'
)
);
ApiEndpoint::create(
'http_method' => 'PUT',
'scopes' => [sprintf('%s/summits/publish-event', $current_realm)],
),
array(
'name' => 'unpublish-event',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/events/{event_id}/publish',
'http_method' => 'DELETE'
)
);
ApiEndpoint::create(
'http_method' => 'DELETE',
'scopes' => [sprintf('%s/summits/publish-event', $current_realm)],
),
array(
'name' => 'delete-event',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/events/{event_id}',
'http_method' => 'DELETE'
)
);
ApiEndpoint::create(
'http_method' => 'DELETE',
'scopes' => [sprintf('%s/summits/delete-event', $current_realm)],
),
array(
'name' => 'add-event-feedback',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/events/{event_id}/feedback',
'http_method' => 'POST'
)
);
ApiEndpoint::create(
'http_method' => 'POST',
'scopes' => [sprintf('%s/summits/write', $current_realm)],
),
array(
'name' => 'add-event-feedback-v2',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v2/summits/{id}/events/{event_id}/feedback',
'http_method' => 'POST'
)
);
ApiEndpoint::create(
'http_method' => 'POST',
'scopes' => [sprintf('%s/summits/write', $current_realm)],
),
array(
'name' => 'get-event-feedback',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/events/{event_id}/feedback/{attendee_id?}',
'http_method' => 'GET'
)
);
// locations
ApiEndpoint::create(
array(
'name' => 'get-locations',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/locations',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [sprintf('%s/summits/read', $current_realm)],
),
// locations
array(
'name' => 'get-locations',
'route' => '/api/v1/summits/{id}/locations',
'http_method' => 'GET',
'scopes' => [sprintf('%s/summits/read', $current_realm)],
),
array(
'name' => 'get-venues',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/locations/venues',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [sprintf('%s/summits/read', $current_realm)],
),
array(
'name' => 'get-external-locations',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/locations/external-locations',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [sprintf('%s/summits/read', $current_realm)],
),
array(
'name' => 'get-hotels',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/locations/hotels',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [sprintf('%s/summits/read', $current_realm)],
),
array(
'name' => 'get-airports',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/locations/airports',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [sprintf('%s/summits/read', $current_realm)],
),
array(
'name' => 'get-location',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/locations/{location_id}',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [sprintf('%s/summits/read', $current_realm)],
),
array(
'name' => 'get-location-events',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/locations/{location_id}/events',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [sprintf('%s/summits/read', $current_realm)],
),
array(
'name' => 'get-location-published-events',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/locations/{location_id}/events/published',
'http_method' => 'GET'
)
);
// event types
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [sprintf('%s/summits/read', $current_realm)],
),
// event types
array(
'name' => 'get-event-types',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/event-types',
'http_method' => 'GET'
)
);
//summit types
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [sprintf('%s/summits/read', $current_realm)],
),
//summit types
array(
'name' => 'get-summit-types',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/summit-types',
'http_method' => 'GET'
)
);
//external orders
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [sprintf('%s/summits/read', $current_realm)],
),
//external orders
array(
'name' => 'get-external-order',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/external-orders/{external_order_id}',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [sprintf('%s/summits/read-external-orders', $current_realm)],
),
array(
'name' => 'confirm-external-order',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/external-orders/{external_order_id}/external-attendees/{external_attendee_id}/confirm',
'http_method' => 'POST'
)
);
//videos
ApiEndpoint::create(
'http_method' => 'POST',
'scopes' => [sprintf('%s/summits/confirm-external-orders', $current_realm)],
),
//videos
array(
'name' => 'get-presentation-videos',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/presentations/{presentation_id}/videos',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [sprintf('%s/summits/read', $current_realm)],
),
array(
'name' => 'get-presentation-video',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/presentations/{presentation_id}/video/{video_id}',
'http_method' => 'GET'
)
);
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [sprintf('%s/summits/read', $current_realm)],
),
array(
'name' => 'create-presentation-video',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/presentations/{presentation_id}/videos',
'http_method' => 'POST'
)
);
ApiEndpoint::create(
'http_method' => 'POST',
'scopes' => [sprintf('%s/summits/write-videos', $current_realm)],
),
array(
'name' => 'update-presentation-video',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/presentations/{presentation_id}/videos/{video_id}',
'http_method' => 'PUT'
)
);
ApiEndpoint::create(
'http_method' => 'PUT',
'scopes' => [sprintf('%s/summits/write-videos', $current_realm)],
),
array(
'name' => 'delete-presentation-video',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/presentations/{presentation_id}/videos/{video_id}',
'http_method' => 'DELETE'
)
);
//members
ApiEndpoint::create(
'http_method' => 'DELETE',
'scopes' => [sprintf('%s/summits/write-videos', $current_realm)],
),
//members
array(
'name' => 'get-own-member',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/members/me',
'http_method' => 'GET'
)
);
// notifications
ApiEndpoint::create(
'http_method' => 'GET',
'scopes' => [sprintf('%s/me/read', $current_realm)],
),
// notifications
array(
'name' => 'get-notifications',
'active' => true,
'api_id' => $summit->id,
'route' => '/api/v1/summits/{id}/notifications',
'http_method' => 'GET'
'http_method' => 'GET',
'scopes' => [sprintf('%s/summits/read-notifications', $current_realm)],
)
);
$member_read_scope = ApiScope::where('name', '=', sprintf('%s/me/read', $current_realm))->first();
$summit_read_scope = ApiScope::where('name', '=', sprintf('%s/summits/read', $current_realm))->first();
$summit_write_scope = ApiScope::where('name', '=', sprintf('%s/summits/write', $current_realm))->first();
$summit_write_event_scope = ApiScope::where('name', '=', sprintf('%s/summits/write-event', $current_realm))->first();
$summit_publish_event_scope = ApiScope::where('name', '=', sprintf('%s/summits/publish-event', $current_realm))->first();
$summit_delete_event_scope = ApiScope::where('name', '=', sprintf('%s/summits/delete-event', $current_realm))->first();
$summit_external_order_read = ApiScope::where('name', '=', sprintf('%s/summits/read-external-orders', $current_realm))->first();
$summit_external_order_confirm = ApiScope::where('name', '=', sprintf('%s/summits/confirm-external-orders', $current_realm))->first();
$write_videos_scope = ApiScope::where('name', '=', sprintf('%s/summits/write-videos', $current_realm))->first();
$read_notifications = ApiScope::where('name', '=', sprintf('%s/summits/read-notifications', $current_realm))->first();
// read
$endpoint = ApiEndpoint::where('name', '=', 'get-summits')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-own-member')->first();
$endpoint->scopes()->attach($member_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-summit')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-summit-entity-events')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-attendees')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-attendee')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-attendee-schedule')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'add-event-attendee-schedule')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-speakers')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-speaker')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-events')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-published-events')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-all-events')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-all-published-events')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-event')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-published-event')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-event-feedback')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-locations')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-venues')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-hotels')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-airports')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-external-locations')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-location')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-event-types')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-summit-types')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-location-published-events')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-location-events')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-presentation-videos')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'get-presentation-video')->first();
$endpoint->scopes()->attach($summit_read_scope->id);
// read external orders
$endpoint = ApiEndpoint::where('name', '=', 'get-external-order')->first();
$endpoint->scopes()->attach($summit_external_order_read->id);
// read notifications
$endpoint = ApiEndpoint::where('name', '=', 'get-notifications')->first();
$endpoint->scopes()->attach($read_notifications->id);
// write
$endpoint = ApiEndpoint::where('name', '=', 'delete-event-attendee-schedule')->first();
$endpoint->scopes()->attach($summit_write_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'checking-event-attendee-schedule')->first();
$endpoint->scopes()->attach($summit_write_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'add-speaker-feedback')->first();
$endpoint->scopes()->attach($summit_write_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'add-event-feedback')->first();
$endpoint->scopes()->attach($summit_write_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'add-event-feedback-v2')->first();
$endpoint->scopes()->attach($summit_write_scope->id);
// write events
$endpoint = ApiEndpoint::where('name', '=', 'add-event')->first();
$endpoint->scopes()->attach($summit_write_event_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'update-event')->first();
$endpoint->scopes()->attach($summit_write_event_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'publish-event')->first();
$endpoint->scopes()->attach($summit_publish_event_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'unpublish-event')->first();
$endpoint->scopes()->attach($summit_publish_event_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'delete-event')->first();
$endpoint->scopes()->attach($summit_delete_event_scope->id);
//confirm external order
$endpoint = ApiEndpoint::where('name', '=', 'confirm-external-order')->first();
$endpoint->scopes()->attach($summit_external_order_confirm->id);
//write videos
$endpoint = ApiEndpoint::where('name', '=', 'create-presentation-video')->first();
$endpoint->scopes()->attach($write_videos_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'update-presentation-video')->first();
$endpoint->scopes()->attach($write_videos_scope->id);
$endpoint = ApiEndpoint::where('name', '=', 'delete-presentation-video')->first();
$endpoint->scopes()->attach($write_videos_scope->id);
]);
}

View File

@ -13,14 +13,15 @@
**/
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\Config;
use models\resource_server\Api;
use models\resource_server\ApiScope;
use Illuminate\Support\Facades\Config;;
use App\Models\ResourceServer\ApiScope;
use LaravelDoctrine\ORM\Facades\EntityManager;
use Illuminate\Support\Facades\DB;
/**
* Class ApiScopesSeeder
*/
class ApiScopesSeeder extends Seeder
final class ApiScopesSeeder extends Seeder
{
public function run()
@ -38,158 +39,128 @@ class ApiScopesSeeder extends Seeder
{
$current_realm = Config::get('app.url');
$public_clouds = Api::where('name', '=', 'public-clouds')->first();
$api = EntityManager::getRepository(\App\Models\ResourceServer\Api::class)->findOneBy(['name' => 'public-clouds']);
ApiScope::create(
array(
'name' => sprintf('%s/public-clouds/read', $current_realm),
'short_description' => 'Get Public Clouds',
'description' => 'Grants read only access for Public Clouds',
'api_id' => $public_clouds->id,
'system' => false
)
);
$scope = new ApiScope();
$scope->setName(sprintf('%s/public-clouds/read', $current_realm));
$scope->setShortDescription('Read Public Clouds Data');
$scope->setDescription('Grants read only access for Public Clouds');
$scope->setActive(true);
$scope->setDefault(false);
$scope->setApi($api);
EntityManager::persist($scope);
EntityManager::flush();
}
private function seedPrivateCloudScopes()
{
$current_realm = Config::get('app.url');
$private_clouds = Api::where('name', '=', 'private-clouds')->first();
$api = EntityManager::getRepository(\App\Models\ResourceServer\Api::class)->findOneBy(['name' => 'private-clouds']);
ApiScope::create(
array(
'name' => sprintf('%s/private-clouds/read', $current_realm),
'short_description' => 'Get Private Clouds',
'description' => 'Grants read only access for Private Clouds',
'api_id' => $private_clouds->id,
'system' => false
)
);
$scope = new ApiScope();
$scope->setName(sprintf('%s/private-clouds/read', $current_realm));
$scope->setShortDescription('Read Private Clouds Data');
$scope->setDescription('Grants read only access for Private Clouds');
$scope->setActive(true);
$scope->setDefault(false);
$scope->setApi($api);
EntityManager::persist($scope);
EntityManager::flush();
}
private function seedConsultantScopes()
{
$current_realm = Config::get('app.url');
$consultants = Api::where('name', '=', 'consultants')->first();
$api = EntityManager::getRepository(\App\Models\ResourceServer\Api::class)->findOneBy(['name' => 'consultants']);
ApiScope::create(
array(
'name' => sprintf('%s/consultants/read', $current_realm),
'short_description' => 'Get Consultants',
'description' => 'Grants read only access for Consultants',
'api_id' => $consultants->id,
'system' => false
)
);
$scope = new ApiScope();
$scope->setName(sprintf('%s/consultants/read', $current_realm));
$scope->setShortDescription('Read Consultants Data');
$scope->setDescription('Grants read only access for Consultants');
$scope->setActive(true);
$scope->setDefault(false);
$scope->setApi($api);
EntityManager::persist($scope);
EntityManager::flush();
}
private function seedSummitScopes()
{
$current_realm = Config::get('app.url');
$summits = Api::where('name', '=', 'summits')->first();
$api = EntityManager::getRepository(\App\Models\ResourceServer\Api::class)->findOneBy(['name' => 'summits']);
ApiScope::create(
$scopes = [
array(
'name' => sprintf('%s/summits/read', $current_realm),
'short_description' => 'Get Summit Data',
'description' => 'Grants read only access for Summits Data',
'api_id' => $summits->id,
'system' => false
)
);
ApiScope::create(
),
array(
'name' => sprintf('%s/me/read', $current_realm),
'short_description' => 'Get own member data',
'description' => 'Grants read only access for our own member data',
'api_id' => $summits->id,
'system' => false
)
);
ApiScope::create(
),
array(
'name' => sprintf('%s/summits/write', $current_realm),
'short_description' => 'Write Summit Data',
'description' => 'Grants write access for Summits Data',
'api_id' => $summits->id,
'system' => false
)
);
ApiScope::create(
),
array(
'name' => sprintf('%s/summits/write-event', $current_realm),
'short_description' => 'Write Summit Events',
'description' => 'Grants write access for Summits Events',
'api_id' => $summits->id,
'system' => false
)
);
ApiScope::create(
),
array(
'name' => sprintf('%s/summits/delete-event', $current_realm),
'short_description' => 'Delete Summit Events',
'description' => 'Grants delete access for Summits Events',
'api_id' => $summits->id,
'system' => false
)
);
ApiScope::create(
),
array(
'name' => sprintf('%s/summits/publish-event', $current_realm),
'short_description' => 'Publish/UnPublish Summit Events',
'description' => 'Grants Publish/UnPublish access for Summits Events',
'api_id' => $summits->id,
'system' => false
)
);
ApiScope::create(
),
array(
'name' => sprintf('%s/summits/read-external-orders', $current_realm),
'short_description' => 'Allow to read External Orders',
'description' => 'Allow to read External Orders',
'api_id' => $summits->id,
'system' => false
)
);
ApiScope::create(
),
array(
'name' => sprintf('%s/summits/confirm-external-orders', $current_realm),
'short_description' => 'Allow to confirm External Orders',
'description' => 'Allow to confirm External Orders',
'api_id' => $summits->id,
'system' => false
)
);
ApiScope::create(
),
array(
'name' => sprintf('%s/summits/write-videos', $current_realm),
'short_description' => 'Allow to write presentation videos',
'description' => 'Allow to write presentation videos',
'api_id' => $summits->id,
'system' => false
)
);
ApiScope::create(
),
array(
'name' => sprintf('%s/summits/read-notifications', $current_realm),
'short_description' => 'Allow to read summit notifications',
'description' => 'Allow to read summit notifications',
'api_id' => $summits->id,
'system' => false
)
);
];
foreach ($scopes as $scope_info) {
$scope = new ApiScope();
$scope->setName($scope_info['name']);
$scope->setShortDescription($scope_info['short_description']);
$scope->setDescription($scope_info['description']);
$scope->setActive(true);
$scope->setDefault(false);
$scope->setApi($api);
EntityManager::persist($scope);
}
EntityManager::flush();
}
}

View File

@ -11,8 +11,11 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
use Illuminate\Database\Seeder;
use models\resource_server\Api;
use App\Models\ResourceServer\Api;
use LaravelDoctrine\ORM\Facades\EntityManager;
use Illuminate\Support\Facades\DB;
/**
* Class ApisTableSeeder
@ -27,37 +30,43 @@ final class ApiSeeder extends Seeder
DB::table('api_scopes')->delete();
DB::table('api_endpoints')->delete();
DB::table('apis')->delete();
// public clouds
Api::create(
array(
'name' => 'public-clouds',
'active' => true,
'Description' => 'Marketplace Public Clouds'
)
);
$api = new Api();
$api->setName('public-clouds');
$api->setActive(true);
$api->setDescription('Marketplace Public Clouds API');
EntityManager::persist($api);
// private clouds
Api::create(
array(
'name' => 'private-clouds',
'active' => true,
'Description' => 'Marketplace Private Clouds'
)
);
$api = new Api();
$api->setName('private-clouds');
$api->setActive(true);
$api->setDescription('Marketplace Private Clouds API');
EntityManager::persist($api);
// consultants
Api::create(
array(
'name' => 'consultants',
'active' => true,
'Description' => 'Marketplace Consultants'
)
);
$api = new Api();
$api->setName('consultants');
$api->setActive(true);
$api->setDescription('Marketplace Consultants API');
EntityManager::persist($api);
// summit
Api::create(
array(
'name' => 'summits',
'active' => true,
'Description' => 'Summits'
)
);
$api = new Api();
$api->setName('summits');
$api->setActive(true);
$api->setDescription('Summit API');
EntityManager::persist($api);
EntityManager::flush();
}
}

View File

@ -3,7 +3,10 @@
use Illuminate\Database\Seeder;
use Illuminate\Database\Eloquent\Model;
class DatabaseSeeder extends Seeder
/**
* Class DatabaseSeeder
*/
final class DatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
@ -13,7 +16,7 @@ class DatabaseSeeder extends Seeder
public function run()
{
// $this->call(UsersTableSeeder::class);
Model::unguard();
Model::unguard();
$this->call('ApiSeeder');
$this->call('ApiScopesSeeder');
$this->call('ApiEndpointsSeeder');

View File

@ -18,7 +18,7 @@ use Illuminate\Database\Seeder;
/**
* Class TestSeeder
*/
class TestSeeder extends Seeder
final class TestSeeder extends Seeder
{
public function run()
{

View File

@ -1,2 +0,0 @@
*
!.gitignore

View File

@ -140,7 +140,7 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
public function testCurrentSummitMyAttendeeFail404()
{
App::singleton('models\resource_server\IAccessTokenService', 'AccessTokenServiceStub2');
App::singleton('App\Models\ResourceServer\IAccessTokenService', 'AccessTokenServiceStub2');
$params = array
(
@ -1095,8 +1095,8 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
{
$params = array
(
'id' => 6,
'event_id' => 15027,
'id' => 7,
'event_id' => 17300,
);
$headers = array
@ -1112,7 +1112,6 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
'attendee_id' => 'me'
);
$response = $this->action
(
"POST",
@ -1360,12 +1359,12 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
public function testGetEventFeedback()
{
$this->testAddFeedback2Event();
//$this->testAddFeedback2Event();
$params = array
(
'id' => 6,
'event_id' => 9454,
'id' => 7,
'event_id' => 17300,
);
$headers = array
@ -1390,6 +1389,23 @@ final class OAuth2SummitApiTest extends ProtectedApiTest
$feedback = json_decode($content);
$this->assertTrue(!is_null($feedback));
$response = $this->action
(
"GET",
"OAuth2SummitEventsApiController@getEventFeedback",
$params,
array('expand' => 'owner'),
array(),
array(),
$headers
);
$content = $response->getContent();
$this->assertResponseStatus(200);
$feedback = json_decode($content);
$this->assertTrue(!is_null($feedback));
}
public function testGetMeEventFeedback()

View File

@ -15,7 +15,7 @@
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Config;
use models\oauth2\AccessToken;
use models\resource_server\IAccessTokenService;
use App\Models\ResourceServer\IAccessTokenService;
/**
* Class AccessTokenServiceStub
@ -102,7 +102,7 @@ abstract class ProtectedApiTest extends TestCase
public function createApplication()
{
$app = parent::createApplication();
App::singleton('models\resource_server\IAccessTokenService', 'AccessTokenServiceStub');
App::singleton('App\Models\ResourceServer\IAccessTokenService', 'AccessTokenServiceStub');
return $app;
}

View File

@ -12,7 +12,7 @@
* See the License for the specific language governing permissions and
* limitations under the License.
**/
class ServicesTest extends TestCase
class ServicesTest extends TestCase
{
public function testAccessTokenService(){
$cache = App::make('libs\utils\ICacheService');
@ -32,7 +32,7 @@ class ServicesTest extends TestCase
];
$cache->storeHash(md5($token_value), $token_info, $cache_lifetime );
sleep(10);
$service = App::make('models\resource_server\IAccessTokenService');
$service = App::make('App\Models\ResourceServer\IAccessTokenService');
$service->get($token_value);
}
}