Skip to content

Commit

Permalink
Merge pull request #85 from symfonycorp/handle-legacy-url
Browse files Browse the repository at this point in the history
 Better handle the legacy URL to warn users
  • Loading branch information
tgalopin committed May 25, 2020
2 parents a44b6a4 + aed69c7 commit bb31de9
Show file tree
Hide file tree
Showing 35 changed files with 127 additions and 118 deletions.
3 changes: 2 additions & 1 deletion Cli/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of the SensioLabsInsight package.
*
* (c) SensioLabs <contact@sensiolabs.com>
* (c) SensioLabs <support@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down Expand Up @@ -51,6 +51,7 @@ public function getApi()
if (\array_key_exists('api_endpoint', $config)) {
$config['base_url'] = $config['api_endpoint'];
}

$this->api = new Api($config);

if ($this->logFile) {
Expand Down
2 changes: 1 addition & 1 deletion Cli/Command/AnalysisCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of the SensioLabsInsight package.
*
* (c) SensioLabs <contact@sensiolabs.com>
* (c) SensioLabs <support@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
12 changes: 11 additions & 1 deletion Cli/Command/AnalyzeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of the SensioLabsInsight package.
*
* (c) SensioLabs <contact@sensiolabs.com>
* (c) SensioLabs <support@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand All @@ -12,11 +12,13 @@
namespace SensioLabs\Insight\Cli\Command;

use SensioLabs\Insight\Cli\Helper\DescriptorHelper;
use SensioLabs\Insight\Sdk\Api;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;

class AnalyzeCommand extends Command implements NeedConfigurationInterface
{
Expand All @@ -37,7 +39,15 @@ protected function configure()
protected function execute(InputInterface $input, OutputInterface $output)
{
$projectUuid = $input->getArgument('project-uuid');

/** @var Api $api */
$api = $this->getApplication()->getApi();

if (false !== strpos($api->getBaseUrl(), '.sensiolabs.com')) {
$io = new SymfonyStyle($input, $output);
$io->warning('You are using the legacy URL of SymfonyInsight which may stop working in the future. You should reconfigure this tool by running the "configure" command and use "https://insight.symfony.com" as endpoint.');
}

$analysis = $api->analyze($projectUuid, $input->getOption('reference'), $input->getOption('branch'));

$chars = ['-', '\\', '|', '/'];
Expand Down
2 changes: 1 addition & 1 deletion Cli/Command/ConfigureCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of the SensioLabsInsight package.
*
* (c) SensioLabs <contact@sensiolabs.com>
* (c) SensioLabs <support@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion Cli/Command/NeedConfigurationInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of the SensioLabsInsight package.
*
* (c) SensioLabs <contact@sensiolabs.com>
* (c) SensioLabs <support@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion Cli/Command/ProjectsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of the SensioLabsInsight package.
*
* (c) SensioLabs <contact@sensiolabs.com>
* (c) SensioLabs <support@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion Cli/Command/SelfUpdateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of the SensioLabsInsight package.
*
* (c) SensioLabs <contact@sensiolabs.com>
* (c) SensioLabs <support@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion Cli/Descriptor/AbstractDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of the SensioLabsInsight package.
*
* (c) SensioLabs <contact@sensiolabs.com>
* (c) SensioLabs <support@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion Cli/Descriptor/JsonDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of the SensioLabsInsight package.
*
* (c) SensioLabs <contact@sensiolabs.com>
* (c) SensioLabs <support@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion Cli/Descriptor/TextDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of the SensioLabsInsight package.
*
* (c) SensioLabs <contact@sensiolabs.com>
* (c) SensioLabs <support@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion Cli/Descriptor/XmlDescriptor.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of the SensioLabsInsight package.
*
* (c) SensioLabs <contact@sensiolabs.com>
* (c) SensioLabs <support@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
41 changes: 25 additions & 16 deletions Cli/Helper/ConfigurationHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
use Symfony\Component\Console\Question\Question;
use Symfony\Component\Console\Style\SymfonyStyle;

class ConfigurationHelper extends Helper
{
private $apiEndpoint;

public function __construct($apiEndpoint)
public function __construct(string $apiEndpoint)
{
$this->apiEndpoint = $apiEndpoint;
}
Expand All @@ -24,12 +25,24 @@ public function updateConfigurationManually(InputInterface $input, OutputInterfa

$userUuid = $input->getOption('user-uuid') ?: $configuration->getUserUuid();
$apiToken = $input->getOption('api-token') ?: $configuration->getApiToken();
$apiEndpoint = $input->getOption('api-endpoint') ?: $configuration->getApiEndpoint();

// Avoid saving again a legacy URL
$defaultEndpoint = $configuration->getApiEndpoint();
if (false !== strpos($defaultEndpoint, '.sensiolabs.com')) {
$defaultEndpoint = null;
}

$apiEndpoint = $input->getOption('api-endpoint') ?: $defaultEndpoint;

$configuration->setUserUuid($this->askValue($input, $output, 'User Uuid', $userUuid));
$configuration->setApiToken($this->askValue($input, $output, 'Api Token', $apiToken));
$configuration->setApiEndpoint($this->askValue($input, $output, 'Api Endpoint', $apiEndpoint ?: $this->apiEndpoint));

if (false !== strpos($configuration->getApiEndpoint(), '.sensiolabs.com')) {
$io = new SymfonyStyle($input, $output);
$io->warning('You are using the legacy URL of SymfonyInsight which may stop working in the future. You should reconfigure this tool by running the "configure" command and use "https://insight.symfony.com" as endpoint.');
}

$this->saveConfiguration($input, $output, $configuration);
}

Expand All @@ -43,7 +56,7 @@ public function getConfiguration(InputInterface $input, OutputInterface $output)
$this->resolveValue($input, $output, $configuration, 'Api Endpoint', $this->apiEndpoint);

if (!$configuration->equals($previousConfiguration)) {
$this->saveConfiguration($input, $output, $configuration, $previousConfiguration);
$this->saveConfiguration($input, $output, $configuration);
}

return $configuration;
Expand Down Expand Up @@ -78,7 +91,6 @@ private function resolveValue(InputInterface $input, OutputInterface $output, Co
private function getValue(InputInterface $input, $varName)
{
$envVarName = sprintf('INSIGHT_%s', str_replace(' ', '_', strtoupper($varName)));

if ($value = getenv($envVarName)) {
return $value;
}
Expand All @@ -90,7 +102,7 @@ private function getValue(InputInterface $input, $varName)

private function askValue(InputInterface $input, OutputInterface $output, $varname, $default = null)
{
$validator = function ($v) use ($varname) {
$validator = static function ($v) use ($varname) {
if (!$v) {
throw new \InvalidArgumentException(sprintf('Your must provide a %s!', $varname));
}
Expand All @@ -99,18 +111,17 @@ private function askValue(InputInterface $input, OutputInterface $output, $varna
};

if (!$input->isInteractive()) {
return \call_user_func($validator, $default);
return $validator($default);
}

if ($default) {
$question = new Question(sprintf('What is your %s? [%s] ', $varname, $default));
} else {
$question = new Question(sprintf('What is your %s? ', $varname));
}
$question = new Question(
$default ? sprintf('What is your %s? [%s] ', $varname, $default) : sprintf('What is your %s? ', $varname),
$default
);

$dialog = $this->getHelperSet()->get('question');
$question->setValidator($validator);

return $dialog->ask($input, $output, $question, $validator, false, $default);
return $this->getHelperSet()->get('question')->ask($input, $output, $question);
}

private function saveConfiguration(InputInterface $input, OutputInterface $output, Configuration $configuration)
Expand All @@ -123,9 +134,7 @@ private function saveConfiguration(InputInterface $input, OutputInterface $outpu

$question = new ConfirmationQuestion('Do you want to save this new configuration? [Y/n] ');

$dialog = $this->getHelperSet()->get('question');

if ($dialog->ask($input, $output, $question)) {
if ($this->getHelperSet()->get('question')->ask($input, $output, $question)) {
$configuration->save();
}
}
Expand Down
2 changes: 1 addition & 1 deletion Cli/Helper/DescriptorHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of the SensioLabsInsight package.
*
* (c) SensioLabs <contact@sensiolabs.com>
* (c) SensioLabs <support@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
2 changes: 1 addition & 1 deletion Cli/Helper/FailConditionHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/*
* This file is part of the SensioLabsInsight package.
*
* (c) SensioLabs <contact@sensiolabs.com>
* (c) SensioLabs <support@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
Expand Down
55 changes: 14 additions & 41 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
SensioLabsInsight SDK
=====================
SymfonyInsight SDK
==================

About
-----

This is the official SDK for the SensioLabsInsight API.
This is the official SDK for the [SymfonyInsight](https://insight.symfony.com/) API.

Installation
------------
Expand All @@ -16,8 +16,7 @@ To install the SDK, run the command below and you will get the latest version:
Command Line Tool
-----------------

The easiest way to use the SensioLabsInsight API is via the built-in command
line tool.
The easiest way to use the SymfonyInsight API is via the built-in command line tool.

A phar version of the command line tool exists to avoid installation of this
project. Download it, then use it like the command line tool:
Expand All @@ -33,8 +32,9 @@ List all the projects in your account:

$ php insight.phar projects

The first time, you will be prompted for your SensioLabsInsight API key and
user UUID (which can be found under the "Account" section on the website).
The first time, you will be prompted for your SymfonyInsight API key and
user UUID (which can be found under the ["Account" section](https://insight.symfony.com/account) on the website).

These information are then stored locally, but can still be overridden via the
`--api-token` and `--user-uuid` options.

Expand All @@ -59,35 +59,6 @@ Configuration
'user_uuid' => 'your user uuid',
));

If you want, you can give a `Guzzle\Http\Client` and a
`Psr\Log\LoggerInterface` to this library:

use Guzzle\Http\Client;
use Monolog\Logger;
use Monolog\Handler\StreamHandler;

$config = array(
'api_token' => 'your api token',
'user_uuid' => 'your user uuid',
)

$client = new Client();

$logger = new Logger('insight-sdk');
$logger->pushHandler(new StreamHandler(__DIR__.'/insight-sdk.log', Logger::DEBUG));

$api = new Api($config, $client, null, $logger);

You can also give a `cache` folder. The SDK will only cache metadatas for
serialization. And you can also give a `debug` flag:

$api = new Api(array(
'api_token' => 'your api token',
'user_uuid' => 'your user uuid',
'cache' => __DIR__.'/cache/insight',
'debug' => true,
));

Usage
-----

Expand Down Expand Up @@ -157,13 +128,15 @@ If something went wrong, an

Jenkins/Hudson Integration
--------------------------
Thanks to [Jenkins PMD Plugin](https://wiki.jenkins-ci.org/display/JENKINS/PMD+Plugin) and SensioLabsInsight SDK PMD output you can easily
embed SensioLabsInsight reports into your build workflow, following these steps:

*It is assumed you already have your project up and building in Jenkins and SensioLabsInsight SDK installed*
Thanks to [Jenkins PMD Plugin](https://wiki.jenkins-ci.org/display/JENKINS/PMD+Plugin) and
SymfonyInsight SDK PMD output you can easily embed SymfonyInsight reports into your build
workflow, following these steps:

*It is assumed you already have your project up and building in Jenkins and SymfonyInsight SDK installed*.

1. Retrieve your `SensioLabsInsight API Token`, `User UUID` and `Project UUID`
on your [account page](https://insight.sensiolabs.com/account)
1. Retrieve your `SymfonyInsight API Token`, `User UUID` and `Project UUID`
on your [account page](https://insight.symfony.com/account)
2. Install the Jenkins `PMD plugin`:
[How to install a jenkins plugin](https://wiki.jenkins-ci.org/display/JENKINS/Plugins#Plugins-Howtoinstallplugins)
3. Optionally you can also install the `EnvInject Plugin`
Expand Down
Loading

0 comments on commit bb31de9

Please sign in to comment.