diff --git a/api-backend/.env b/api-backend/.env index e8ed901d692f374c3e69bce2e8bf258d80817039..2bdbbea515fa2bb72ca17008a17ba0b6461f0a5f 100644 --- a/api-backend/.env +++ b/api-backend/.env @@ -5,7 +5,8 @@ API_URL=https://url.arai-usuarios/api API_LOG_LEVEL=DEBUG API_LOG_HANDLER=errorlog - +API_BASIC_CLIENTES=[["admin", "admin"]] +API_BASIC_SERVIDOR=On ###### CONFIG INSTITUCION ###### INSTITUCION_URL=http://institucion.edu.ar diff --git a/api-backend/config/parameters.yml b/api-backend/config/parameters.yml index 2be0ae2680eb09e1c9005a2350815c4552077c16..b3e3d140d691a7bb13e0e8c5e4184150bbad23f5 100644 --- a/api-backend/config/parameters.yml +++ b/api-backend/config/parameters.yml @@ -10,7 +10,16 @@ api: log: level: $env(API_LOG_LEVEL)$ handler: $env(API_LOG_HANDLER)$ - + basic: + clientes: $env(API_BASIC_CLIENTES)$ + servidor: $env(API_BASIC_SERVIDOR)$ + transport: $env(API_TRANSPORT)$ + queue: + simple_mail: + retries: $env(QUEUE_SIMPLE_MAIL_REINTENTOS)$ + delay: $env(QUEUE_SIMPLE_MAIL_RETRASO)$ + expiration: $env(QUEUE_SIMPLE_MAIL_EXPIRACION)$ + priority: $env(QUEUE_SIMPLE_MAIL_PRIORIDAD)$ services: db: host: $env(DB_HOST)$ diff --git a/api-backend/src/UNAM/Tupa/Backend/API/Authentication/ProviderApi.php b/api-backend/src/UNAM/Tupa/Backend/API/Authentication/ProviderApi.php index 4353550e0c41ce2c5749ffb85407c45282cc6f13..d04ce759560649d7ebe8b68e2250d278b1bba051 100644 --- a/api-backend/src/UNAM/Tupa/Backend/API/Authentication/ProviderApi.php +++ b/api-backend/src/UNAM/Tupa/Backend/API/Authentication/ProviderApi.php @@ -1,11 +1,18 @@ <?php namespace UNAM\Tupa\Backend\API\Authentication; -use UNAM\Tupa\Backend\API\Factory; use SIUToba\rest\seguridad\autenticacion\usuarios_usuario_password; +use UNAM\Tupa\Backend\API\Config\APIConfiguracion; class ProviderApi implements usuarios_usuario_password { + protected $configuration; + + public function __construct(APIConfiguracion $configuration) + { + $this->configuration = $configuration; + } + /** * Dado el username, retorna el password para ser comparado. * @@ -15,17 +22,15 @@ class ProviderApi implements usuarios_usuario_password */ public function get_password($usuario) { - $c = Factory::getContainer()['config']; - $defaultUser = $c['documentos']['api_user']; - $defaultPassword = $c['documentos']['api_pass']; + $clientes = json_decode($this->configuration->getApiClientesBasic(), true); - if ($usuario == $defaultUser) { - return $defaultPassword; + if (! is_array($clientes) || count($clientes) < 1){ + return null; } - $clientes = $c['rest_conf']['clientes']; - - if (isset($clientes[$usuario])) { - return $clientes[$usuario]; + foreach ($clientes as [$user, $pass]) { + if ($user == $usuario) { + return $pass; + } } return null; @@ -36,10 +41,12 @@ class ProviderApi implements usuarios_usuario_password */ public function es_valido($user, $pass) { - return true; - if ($this->get_password($user) == $pass) { - return true; + $passwordAlmacenada = $this->get_password($user); + + if (null === $passwordAlmacenada) { + return false; } - return false; + + return $pass == $passwordAlmacenada; } } diff --git a/api-backend/www/api.php b/api-backend/www/api.php index b243a939d045870be709ae5f5820126ba93989cb..4fd91ad7368021f756dc3cdda7b2f77f2e9e88bf 100644 --- a/api-backend/www/api.php +++ b/api-backend/www/api.php @@ -30,18 +30,18 @@ if ($position !== false) { $settings['url_api'] = substr($_SERVER['REQUEST_URI'], 0, $position + strlen($api_path)); } -$rest_backend = new rest($settings); -$rest_backend->set_logger(Factory::getContainer()['api-logger']); +$rest = new rest($settings); +$rest->set_logger(Factory::getContainer()['api-logger']); -$arai_api_usuario = new ProviderApi(); +$apiBasic = new ProviderApi(Factory::getContainer()['configuration']); $metodos = []; -$metodos[] = new autenticacion_basic_http($arai_api_usuario); +$metodos[] = new autenticacion_basic_http($apiBasic); -$rest_backend->container->singleton('autenticador', function () use ($metodos) { +$rest->container->singleton('autenticador', function () use ($metodos) { return $metodos; }); -$rest_backend->container->singleton('autorizador', function () { +$rest->container->singleton('autorizador', function () { return new autorizacion_anonima(); }); @@ -54,4 +54,4 @@ if ($esPedidoDoc) { return; } -$rest_backend->procesar(); +$rest->procesar(); diff --git a/core/src/UNAM/Tupa/Core/Config/Builder/ApiConfigBuilder.php b/core/src/UNAM/Tupa/Core/Config/Builder/ApiConfigBuilder.php index 132c799de6ccbd1a71da0c83b203651a54c48d35..5e0279e4f5a480faf54dc72a8e7a1db5d38e974c 100644 --- a/core/src/UNAM/Tupa/Core/Config/Builder/ApiConfigBuilder.php +++ b/core/src/UNAM/Tupa/Core/Config/Builder/ApiConfigBuilder.php @@ -29,6 +29,12 @@ class ApiConfigBuilder implements ConfigurationInterface ->scalarNode('publica')->isRequired()->end() ->end() ->end() + ->arrayNode('basic') + ->children() + ->scalarNode('clientes')->isRequired()->end() + ->scalarNode('servidor')->isRequired()->end() + ->end() + ->end() ->arrayNode('log') ->children() ->scalarNode('level')->isRequired()->end() diff --git a/core/src/UNAM/Tupa/Core/Config/Configuracion.php b/core/src/UNAM/Tupa/Core/Config/Configuracion.php index 80bdf0fc50a0467090e161cce3f7bfbb7f868f74..d5f0317bc5ff98f8b2f162573c9f644b8eb9fec6 100644 --- a/core/src/UNAM/Tupa/Core/Config/Configuracion.php +++ b/core/src/UNAM/Tupa/Core/Config/Configuracion.php @@ -284,6 +284,16 @@ abstract class Configuracion return $this->getParametroAPI('queue.simple_mail.priority'); } + public function getApiClientesBasic() + { + return $this->getParametroAPI('basic.clientes'); + } + + public function getApiServidorBasic() + { + return $this->getParametroAPI('basic.servidor'); + } + /** * @return mixed * diff --git a/docker/Makefile b/docker/Makefile index f3caabce071bd212fe26085371bbc319947962ce..ae96514514b3cf39443e9e60b099a105245fd1b2 100644 --- a/docker/Makefile +++ b/docker/Makefile @@ -74,10 +74,10 @@ install: recreate-all: ## OjO, borra base de [meta]datos. Crea un entorno nuevo completo. @$(MAKE) clean - @$(MAKE) recreate-all-backend - @$(MAKE) recreate-all-api-backend - @$(MAKE) recreate-all-api-frontend - @$(MAKE) recreate-all-worker + @$(MAKE) recreate-backend + @$(MAKE) recreate-api-backend + @$(MAKE) recreate-api-frontend + @$(MAKE) recreate-worker @echo "================================================================================" @echo "========= Plataforma de servicios TUPA" @echo "================================================================================" diff --git a/docker/api-backend/.env b/docker/api-backend/.env index e8ed901d692f374c3e69bce2e8bf258d80817039..2bdbbea515fa2bb72ca17008a17ba0b6461f0a5f 100644 --- a/docker/api-backend/.env +++ b/docker/api-backend/.env @@ -5,7 +5,8 @@ API_URL=https://url.arai-usuarios/api API_LOG_LEVEL=DEBUG API_LOG_HANDLER=errorlog - +API_BASIC_CLIENTES=[["admin", "admin"]] +API_BASIC_SERVIDOR=On ###### CONFIG INSTITUCION ###### INSTITUCION_URL=http://institucion.edu.ar diff --git a/docker/api-backend/Makefile b/docker/api-backend/Makefile index 68638c2026449d1ace160fbac8c33f4258f3958c..c9c9f01c1c089ba40627bfe91df5969cb8bc336e 100644 --- a/docker/api-backend/Makefile +++ b/docker/api-backend/Makefile @@ -40,7 +40,7 @@ composer-update-api-backend: -v $(COMPOSER_CACHE_DIR_REAL):/tmp/cache:rw \ $(IMAGE_NAME_API_BACKEND) -- composer update $(FLAGS_COMPOSER_API_BACKEND) -recreate-all-api-backend: build-image-api-backend clean-api-backend composer-api-backend +recreate-api-backend: build-image-api-backend clean-api-backend composer-api-backend $(SHOW_DEBUG)docker run -d -it \ -v $(PATH_PROYECTO_HOST):/usr/local/app \ --env-file=$(CONF_FILE_API_BACKEND) \ diff --git a/docker/api-frontend/Makefile b/docker/api-frontend/Makefile index 908b5dd8e8967bf34d2f3c16f32d842723d141f0..fee9f9f5a8a9a60a744a7328a6690f6a69b8df1c 100644 --- a/docker/api-frontend/Makefile +++ b/docker/api-frontend/Makefile @@ -40,7 +40,7 @@ composer-update-api-frontend: -v $(COMPOSER_CACHE_DIR_REAL):/tmp/cache:rw \ $(IMAGE_NAME_API_FRONTEND) -- composer update $(FLAGS_COMPOSER_API_FRONTEND) -recreate-all-api-frontend: build-image-api-frontend clean-api-frontend composer-api-frontend +recreate-api-frontend: build-image-api-frontend clean-api-frontend composer-api-frontend $(SHOW_DEBUG)docker run -d -it \ -v $(PATH_PROYECTO_HOST):/usr/local/app \ --env-file=$(CONF_FILE_API_FRONTEND) \ diff --git a/docker/api-frontend/entrypoint.sh b/docker/api-frontend/entrypoint.sh index b6ec6ef1c4ffaf671fbfacc88df3809d787933a7..f6db1a6f15da779acfb7dda3fe467b7d8b26424e 100644 --- a/docker/api-frontend/entrypoint.sh +++ b/docker/api-frontend/entrypoint.sh @@ -42,7 +42,7 @@ if [[ ${CHANGE_APACHE_USR} = 1 ]]; then fi if [[ ${FIX_PERMISSIONS} = 1 ]]; then - ./api-frontend/bin/instalador permisos:simple -U $APACHE_USER -W apache --no-vendor ${FLAGS_INSTALADOR} + ./api-frontend/bin/instalador permisos:simple -U $APACHE_USER -W apache ${FLAGS_INSTALADOR} fi eval "$@" diff --git a/docker/backend/Makefile b/docker/backend/Makefile index 45e079731a5bf9087e62c932134e3bd399f0750b..f826914679635d5baf5ed5d876b54d33de0846a2 100644 --- a/docker/backend/Makefile +++ b/docker/backend/Makefile @@ -86,7 +86,7 @@ install-backend: recreate-empty-db load-db composer-backend fixwc -e APACHE_RUN_GROUP=$(shell id -g) \ --name=$(INSTANCIA_BACKEND) $(IMAGE_NAME_BACKEND) --reinstalar $(FLAGS_INSTALAR) $(RUN_CMD) -recreate-all-backend: build-image-backend clean-backend +recreate-backend: build-image-backend clean-backend @$(MAKE) install-backend $(SHOW_DEBUG)docker run -d -it \ -v $(PATH_PROYECTO_HOST):/usr/local/app \ diff --git a/docker/worker/Dockerfile b/docker/worker/Dockerfile index 5110d93838651bd597a354975e752ffee6887911..5715a754bca767c466ee5e31e8bba6939e0acb15 100644 --- a/docker/worker/Dockerfile +++ b/docker/worker/Dockerfile @@ -21,7 +21,7 @@ RUN echo "composer optimizado" \ # http://naderman.de/slippy/slides/2018-06-01-Composer-Best-Practices-2018.pdf && composer global require hirak/prestissimo -COPY worker/ /usr/local/build/worker +COPY core/ /usr/local/build/core COPY docker/ /usr/local/build/docker COPY version /usr/local/build/version COPY worker/composer.json /usr/local/build/composer.json @@ -31,9 +31,13 @@ RUN echo "composer install" \ # https://getcomposer.org/doc/articles/autoloader-optimization.md && composer dump-autoload --working-dir ./worker --optimize --apcu +COPY worker /usr/local/build/worker + RUN echo "eliminar archivos innecesarios para alivianar la imagen" \ && find . -type d -name ".git" | xargs rm -rf +RUN bash ./docker/api-frontend/entrypoint.sh --fix-permissions + ############################################################################# # stage DEV ############################################################################# diff --git a/docker/worker/Makefile b/docker/worker/Makefile index a2ac0d4d19a5c935d37deec7b45d168b906bad1b..c8824dfbda7f539e16152cfe5e6c19a9b5a02643 100644 --- a/docker/worker/Makefile +++ b/docker/worker/Makefile @@ -46,7 +46,7 @@ composer-update-worker: -v $(COMPOSER_CACHE_DIR_REAL):/tmp/cache:rw \ $(IMAGE_NAME_WORKER) -- composer update $(FLAGS_COMPOSER_WORKER) -recreate-all-worker: build-image-worker clean-worker composer-worker recreate-redis +recreate-worker: build-image-worker clean-worker composer-worker recreate-redis $(SHOW_DEBUG)docker run -d -it \ -v $(PATH_PROYECTO_HOST):/usr/local/app \ --env-file=$(CONF_FILE_WORKER) \ diff --git a/docker/worker/entrypoint.sh b/docker/worker/entrypoint.sh index d0b16e36d47fd7b406998a30617a99c0c9806be6..6ba3648671c795fd8c8d386d5127318ec567cb7e 100644 --- a/docker/worker/entrypoint.sh +++ b/docker/worker/entrypoint.sh @@ -2,13 +2,22 @@ set -e MAIL_SIMPLE=0 +FIX_PERMISSIONS=0 SERVE=0 +CHANGE_APACHE_USR=0 +APACHE_USER=apache break_loop=0 while [[ "$#" -gt 0 && ${break_loop} = 0 ]]; do key="$1" case ${key} in + --fix-permissions) + FIX_PERMISSIONS=1 + ;; + --change-apache-usr) + CHANGE_APACHE_USR=1 + ;; --mail-simple) MAIL_SIMPLE=1 ;; @@ -22,8 +31,18 @@ while [[ "$#" -gt 0 && ${break_loop} = 0 ]]; do shift done +if [[ ${CHANGE_APACHE_USR} = 1 ]]; then + APACHE_USER=op + id -u $APACHE_USER || adduser -D -u $APACHE_RUN_USER $APACHE_USER + sed -i "s/User apache/User op/" /etc/apache2/httpd.conf +fi + if [[ ${MAIL_SIMPLE} = 1 ]]; then ./worker/bin/worker job:send-mail fi +if [[ ${FIX_PERMISSIONS} = 1 ]]; then + chown $APACHE_USER:apache /usr/local/app -R +fi + eval "$@"