Skip to content
This repository was archived by the owner on Jun 25, 2025. It is now read-only.

Commit a8ce930

Browse files
authored
Tested and improved commands for apisearch (#40)
1 parent e739155 commit a8ce930

26 files changed

+502
-234
lines changed

.circleci/config.yml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
version: 2
2+
jobs:
3+
build:
4+
docker:
5+
- image: circleci/php:7.1-cli
6+
- image: redis:4-alpine
7+
8+
- image: "docker.elastic.co/elasticsearch/elasticsearch:6.2.4"
9+
environment:
10+
cluster.name: apisearch
11+
http.host: 0.0.0.0
12+
transport.host: 0.0.0.0
13+
ES_JAVA_OPTS: "-Xms1g -Xmx1g"
14+
node.max_local_storage_nodes: 10
15+
discovery.type: single-node
16+
17+
- image: "apisearchio/search-server:latest"
18+
environment:
19+
APISEARCH_GOD_TOKEN: 0e4d75ba-c640-44c1-a745-06ee51db4e93
20+
APISEARCH_READONLY_TOKEN: 410806ed-f2c2-8d22-96ea-7fb68026df34
21+
APISEARCH_PING_TOKEN: 6326d504-0a5f-f1ae-7344-8e70b75fcde9
22+
APISEARCH_ENABLED_PLUGINS: redis_storage
23+
ELASTICSEARCH_HOST: localhost
24+
ELASTICSEARCH_PORT: 9200
25+
ELASTICSEARCH_REFRESH_ON_WRITE: 1
26+
REDIS_STORAGE_HOST: localhost
27+
REDIS_STORAGE_PORT: 6379
28+
29+
working_directory: ~/project
30+
steps:
31+
- checkout
32+
- run:
33+
name: Run tests
34+
command: |
35+
composer install -n --prefer-dist --no-suggest
36+
sh .circleci/run-tests

.circleci/run-tests

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/bin/bash
2+
3+
exec 6>&-
4+
exec 6<&-
5+
6+
until $(curl --output /dev/null --silent --fail "http://localhost:9200/_cluster/health?wait_for_status=yellow&timeout=10s"); do
7+
echo "$(date) - can't connect to localhost:9200"
8+
sleep 1
9+
done
10+
11+
exec 6>&-
12+
exec 6<&-
13+
14+
composer test

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
vendor
22
composer.lock
3-
composer.lock
3+
composer.lock
4+
var

.php_cs.cache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"php":"7.1.25-1+ubuntu18.04.1+deb.sury.org+1","version":"2.13.2:v2.13.2#ce6c4bbc24302f535c7bbf9ad35fbb0be4f5a4b2","rules":{"blank_line_after_namespace":true,"braces":{"allow_single_line_closure":true},"class_definition":{"single_line":true},"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_constants":true,"lowercase_keywords":true,"method_argument_space":true,"no_break_comment":true,"no_closing_tag":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":true,"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":true,"encoding":true,"full_opening_tag":true,"binary_operator_spaces":true,"blank_line_after_opening_tag":true,"blank_line_before_statement":{"statements":["return"]},"cast_spaces":true,"class_attributes_separation":{"elements":["method"]},"concat_space":{"spacing":"none"},"declare_equal_normalize":true,"function_typehint_space":true,"include":true,"increment_style":true,"lowercase_cast":true,"lowercase_static_reference":true,"magic_constant_casing":true,"magic_method_casing":true,"native_function_casing":true,"new_with_braces":true,"no_blank_lines_after_class_opening":true,"no_blank_lines_after_phpdoc":true,"no_empty_comment":true,"no_empty_phpdoc":true,"no_empty_statement":true,"no_extra_blank_lines":{"tokens":["curly_brace_block","extra","parenthesis_brace_block","square_brace_block","throw","use"]},"no_leading_import_slash":true,"no_leading_namespace_whitespace":true,"no_mixed_echo_print":{"use":"echo"},"no_multiline_whitespace_around_double_arrow":true,"no_short_bool_cast":true,"no_singleline_whitespace_before_semicolons":true,"no_spaces_around_offset":true,"no_trailing_comma_in_list_call":true,"no_trailing_comma_in_singleline_array":true,"no_unneeded_control_parentheses":true,"no_unneeded_curly_braces":true,"no_unneeded_final_method":true,"no_unused_imports":true,"no_whitespace_before_comma_in_array":true,"no_whitespace_in_blank_line":true,"normalize_index_brace":true,"object_operator_without_whitespace":true,"php_unit_fqcn_annotation":true,"phpdoc_align":{"tags":["method","param","property","return","throws","type","var"]},"phpdoc_annotation_without_dot":true,"phpdoc_indent":true,"phpdoc_inline_tag":true,"phpdoc_no_access":true,"phpdoc_no_alias_tag":true,"phpdoc_no_empty_return":true,"phpdoc_no_package":true,"phpdoc_no_useless_inheritdoc":true,"phpdoc_return_self_reference":true,"phpdoc_scalar":true,"phpdoc_separation":true,"phpdoc_single_line_var_spacing":true,"phpdoc_summary":true,"phpdoc_to_comment":true,"phpdoc_trim":true,"phpdoc_types":true,"phpdoc_var_without_name":true,"protected_to_private":true,"return_type_declaration":true,"semicolon_after_instruction":true,"short_scalar_cast":true,"single_blank_line_before_namespace":true,"single_line_comment_style":{"comment_types":["hash"]},"single_quote":true,"space_after_semicolon":{"remove_in_empty_for_expressions":true},"standardize_increment":true,"standardize_not_equals":true,"ternary_operator_spaces":true,"trailing_comma_in_multiline_array":true,"trim_array_spaces":true,"unary_operator_spaces":true,"whitespace_after_comma_in_array":true,"yoda_style":true},"hashes":{"Twig\/MethodAccessorExtension.php":2939807874,"Twig\/AggregationTranslationExtension.php":2415810000,"Twig\/UrlBuilderExtension.php":2201893333,"DependencyInjection\/CompilerPass\/ExporterCompilerPass.php":857546720,"DependencyInjection\/CompilerPass\/ReadTransformerCompilerPass.php":3948110591,"DependencyInjection\/CompilerPass\/WriteTransformerCompilerPass.php":2530587380,"DependencyInjection\/CompilerPass\/RepositoryCompilerPass.php":3890663324,"DependencyInjection\/ApisearchExtension.php":112225700,"DependencyInjection\/ApisearchConfiguration.php":1683145073,"ApisearchBundle.php":3640212495,"Translator\/AggregationTranslator.php":3471296845,"Command\/ExportIndexCommand.php":1321012391,"Command\/ImportIndexCommand.php":1581740785,"Command\/PrintTokensCommand.php":1160843383,"Command\/DeleteTokensCommand.php":1800041030,"Command\/ApisearchCommand.php":2188021223,"Command\/ConfigureIndexCommand.php":1879894960,"Command\/ApisearchFormattedCommand.php":1606549717,"Command\/PrintIndicesCommand.php":2173968207,"Command\/AddTokenCommand.php":1932082409,"Command\/WithRepositoryBucketCommand.php":3882313592,"Command\/WithAppRepositoryBucketCommand.php":2106806880,"Command\/DeleteTokenCommand.php":3019199442,"Command\/CreateIndexCommand.php":3363275462,"Command\/DeleteIndexCommand.php":903943328,"Command\/ResetIndexCommand.php":2081910409,"Tests\/Functional\/ProductReadTransformer.php":1666987200,"Tests\/Functional\/DependencyInjection\/DisableCommandsTest.php":4157959069,"Tests\/Functional\/DependencyInjection\/ApisearchConfigurationTest.php":1623406226,"Tests\/Functional\/DependencyInjection\/CompilerPass\/InMemoryRepositoryCompilerPassTest.php":1181469493,"Tests\/Functional\/DependencyInjection\/CompilerPass\/TransformersCompilerPassTest.php":2186592420,"Tests\/Functional\/DependencyInjection\/CompilerPass\/HttpRepositoryCompilerPassTest.php":4000035678,"Tests\/Functional\/DependencyInjection\/EnableCommandsTest.php":4130981515,"Tests\/Functional\/ProductBothTransformer.php":3061253314,"Tests\/Functional\/ProductWriteTransformer.php":4090808924}}
1+
{"php":"7.1.26-1+ubuntu18.04.1+deb.sury.org+1","version":"2.14.0:v2.14.0#b788ea0af899cedc8114dca7db119c93b6685da2","rules":{"blank_line_after_namespace":true,"braces":{"allow_single_line_closure":true},"class_definition":{"single_line":true},"elseif":true,"function_declaration":true,"indentation_type":true,"line_ending":true,"lowercase_constants":true,"lowercase_keywords":true,"method_argument_space":true,"no_break_comment":true,"no_closing_tag":true,"no_spaces_after_function_name":true,"no_spaces_inside_parenthesis":true,"no_trailing_whitespace":true,"no_trailing_whitespace_in_comment":true,"single_blank_line_at_eof":true,"single_class_element_per_statement":true,"single_import_per_statement":true,"single_line_after_imports":true,"switch_case_semicolon_to_colon":true,"switch_case_space":true,"visibility_required":true,"encoding":true,"full_opening_tag":true,"binary_operator_spaces":true,"blank_line_after_opening_tag":true,"blank_line_before_statement":{"statements":["return"]},"cast_spaces":true,"class_attributes_separation":{"elements":["method"]},"concat_space":{"spacing":"none"},"declare_equal_normalize":true,"function_typehint_space":true,"include":true,"increment_style":true,"lowercase_cast":true,"lowercase_static_reference":true,"magic_constant_casing":true,"magic_method_casing":true,"native_function_casing":true,"new_with_braces":true,"no_blank_lines_after_class_opening":true,"no_blank_lines_after_phpdoc":true,"no_empty_comment":true,"no_empty_phpdoc":true,"no_empty_statement":true,"no_extra_blank_lines":{"tokens":["curly_brace_block","extra","parenthesis_brace_block","square_brace_block","throw","use"]},"no_leading_import_slash":true,"no_leading_namespace_whitespace":true,"no_mixed_echo_print":{"use":"echo"},"no_multiline_whitespace_around_double_arrow":true,"no_short_bool_cast":true,"no_singleline_whitespace_before_semicolons":true,"no_spaces_around_offset":true,"no_trailing_comma_in_list_call":true,"no_trailing_comma_in_singleline_array":true,"no_unneeded_control_parentheses":true,"no_unneeded_curly_braces":true,"no_unneeded_final_method":true,"no_unused_imports":true,"no_whitespace_before_comma_in_array":true,"no_whitespace_in_blank_line":true,"normalize_index_brace":true,"object_operator_without_whitespace":true,"php_unit_fqcn_annotation":true,"phpdoc_align":{"tags":["method","param","property","return","throws","type","var"]},"phpdoc_annotation_without_dot":true,"phpdoc_indent":true,"phpdoc_inline_tag":true,"phpdoc_no_access":true,"phpdoc_no_alias_tag":true,"phpdoc_no_empty_return":true,"phpdoc_no_package":true,"phpdoc_no_useless_inheritdoc":true,"phpdoc_return_self_reference":true,"phpdoc_scalar":true,"phpdoc_separation":true,"phpdoc_single_line_var_spacing":true,"phpdoc_summary":true,"phpdoc_to_comment":true,"phpdoc_trim":true,"phpdoc_types":true,"phpdoc_types_order":{"null_adjustment":"always_last","sort_algorithm":"none"},"phpdoc_var_without_name":true,"protected_to_private":true,"return_type_declaration":true,"semicolon_after_instruction":true,"short_scalar_cast":true,"single_blank_line_before_namespace":true,"single_line_comment_style":{"comment_types":["hash"]},"single_quote":true,"space_after_semicolon":{"remove_in_empty_for_expressions":true},"standardize_increment":true,"standardize_not_equals":true,"ternary_operator_spaces":true,"trailing_comma_in_multiline_array":true,"trim_array_spaces":true,"unary_operator_spaces":true,"whitespace_after_comma_in_array":true,"yoda_style":true},"hashes":{"Twig\/MethodAccessorExtension.php":2939807874,"Twig\/AggregationTranslationExtension.php":2415810000,"Twig\/UrlBuilderExtension.php":2201893333,"DependencyInjection\/CompilerPass\/ExporterCompilerPass.php":857546720,"DependencyInjection\/CompilerPass\/ReadTransformerCompilerPass.php":3948110591,"DependencyInjection\/CompilerPass\/WriteTransformerCompilerPass.php":2530587380,"DependencyInjection\/CompilerPass\/RepositoryCompilerPass.php":2396654015,"DependencyInjection\/ApisearchExtension.php":112225700,"DependencyInjection\/ApisearchConfiguration.php":3701803641,"ApisearchBundle.php":3640212495,"Translator\/AggregationTranslator.php":4238166597,"Command\/ExportIndexCommand.php":1321012391,"Command\/ImportIndexCommand.php":1581740785,"Command\/PrintTokensCommand.php":276913128,"Command\/DeleteTokensCommand.php":1800041030,"Command\/ApisearchCommand.php":2188021223,"Command\/ConfigureIndexCommand.php":1879894960,"Command\/ApisearchFormattedCommand.php":1573978344,"Command\/PrintIndicesCommand.php":2082971206,"Command\/AddTokenCommand.php":3976278823,"Command\/WithRepositoryBucketCommand.php":3882313592,"Command\/WithAppRepositoryBucketCommand.php":3069075073,"Command\/DeleteTokenCommand.php":3019199442,"Command\/CreateIndexCommand.php":244289546,"Command\/DeleteIndexCommand.php":2512043588,"Command\/ResetIndexCommand.php":2081910409,"Tests\/Functional\/ApisearchBundleFunctionalTest.php":3264653550,"Tests\/Functional\/ProductReadTransformer.php":1666987200,"Tests\/Functional\/DependencyInjection\/DisableCommandsTest.php":2956180423,"Tests\/Functional\/DependencyInjection\/ApisearchConfigurationTest.php":271608124,"Tests\/Functional\/DependencyInjection\/CompilerPass\/InMemoryRepositoryCompilerPassTest.php":3052848166,"Tests\/Functional\/DependencyInjection\/CompilerPass\/TransformersCompilerPassTest.php":1388027657,"Tests\/Functional\/DependencyInjection\/CompilerPass\/HttpRepositoryCompilerPassTest.php":2500445244,"Tests\/Functional\/DependencyInjection\/EnableCommandsTest.php":1149363544,"Tests\/Functional\/ProductBothTransformer.php":3061253314,"Tests\/Functional\/Command\/AddDeleteTokensCommandTest.php":67286622,"Tests\/Functional\/Command\/PrintIndicesCommandTest.php":481741707,"Tests\/Functional\/ProductWriteTransformer.php":4090808924}}

.travis.yml

Lines changed: 0 additions & 18 deletions
This file was deleted.

Command/AddTokenCommand.php

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
namespace Apisearch\Command;
1717

18+
use Apisearch\Model\AppUUID;
19+
use Apisearch\Model\IndexUUID;
1820
use Apisearch\Model\Token;
1921
use Apisearch\Model\TokenUUID;
2022
use Ramsey\Uuid\Uuid;
@@ -48,7 +50,7 @@ protected function configure()
4850
Uuid::uuid4()->toString()
4951
)
5052
->addOption(
51-
'index',
53+
'index-name',
5254
null,
5355
InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL,
5456
'Indices',
@@ -136,16 +138,31 @@ protected function getSuccessMessage(
136138
*/
137139
protected function runCommand(InputInterface $input, OutputInterface $output)
138140
{
139-
list($app_id, $indices) = $this->getRepositoryAndIndices($input, $output);
141+
list($appId, $indices) = $this->getRepositoryAndIndices($input, $output);
140142
$endpoints = $this->getEndpoints($input, $output);
141143

144+
$appName = $input->getArgument('app-name');
145+
$this->printInfoMessage(
146+
$output,
147+
$this->getHeader(),
148+
"App name: <strong>{$appName}</strong>"
149+
);
150+
151+
$this->printInfoMessage(
152+
$output,
153+
$this->getHeader(),
154+
"App UUID: <strong>{$appId}</strong>"
155+
);
156+
142157
$this
143158
->repositoryBucket->findRepository($input->getArgument('app-name'))
144159
->addToken(
145160
new Token(
146161
TokenUUID::createById($input->getArgument('uuid')),
147-
(string) $app_id,
148-
$indices,
162+
AppUUID::createById($appId),
163+
array_map(function (string $index) {
164+
return IndexUUID::createById($index);
165+
}, $indices),
149166
$input->getOption('http-referrer'),
150167
$endpoints,
151168
$input->getOption('plugin'),

Command/ApisearchFormattedCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ abstract class ApisearchFormattedCommand extends ApisearchCommand
3232
* execute() method, you set the code to execute by passing
3333
* a Closure to the setCode() method.
3434
*
35-
* @return null|int null or 0 if everything went fine, or an error code
35+
* @return int|null null or 0 if everything went fine, or an error code
3636
*/
3737
protected function execute(InputInterface $input, OutputInterface $output)
3838
{

Command/CreateIndexCommand.php

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,9 @@ protected function configure()
6767
'App name'
6868
)
6969
->addArgument(
70-
'index',
70+
'index-name',
7171
InputArgument::REQUIRED,
72-
'Index'
72+
'Index name'
7373
)
7474
->addOption(
7575
'language',
@@ -134,7 +134,19 @@ protected function getHeader(): string
134134
protected function runCommand(InputInterface $input, OutputInterface $output)
135135
{
136136
$appName = $input->getArgument('app-name');
137-
$indexUUID = IndexUUID::createById($input->getArgument('index'));
137+
$indexName = $input->getArgument('index-name');
138+
$indexArray = $this
139+
->repositoryBucket
140+
->getConfiguration()[$appName]['indices'] ?? [];
141+
142+
if (!isset($indexArray[$indexName])) {
143+
$this->printInfoMessage(
144+
$output,
145+
$this->getHeader(),
146+
'Index does not exist with this name.'
147+
);
148+
}
149+
$indexId = $indexArray[$indexName];
138150

139151
$this->printInfoMessage(
140152
$output,
@@ -145,7 +157,7 @@ protected function runCommand(InputInterface $input, OutputInterface $output)
145157
$this->printInfoMessage(
146158
$output,
147159
$this->getHeader(),
148-
"Index ID: <strong>{$indexUUID->composeUUID()}</strong>"
160+
"Index name: <strong>{$indexName}</strong>"
149161
);
150162

151163
$synonyms = $this
@@ -161,7 +173,7 @@ protected function runCommand(InputInterface $input, OutputInterface $output)
161173
->repositoryBucket
162174
->findRepository($appName)
163175
->createIndex(
164-
$indexUUID,
176+
IndexUUID::createById($indexId),
165177
Config::createFromArray([
166178
'language' => $input->getOption('language'),
167179
'store_searchable_metadata' => !$input->getOption('no-store-searchable-metadata'),

Command/DeleteIndexCommand.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ protected function configure()
4040
'App name'
4141
)
4242
->addArgument(
43-
'index',
43+
'index-name',
4444
InputArgument::REQUIRED,
45-
'Index'
45+
'Index name'
4646
);
4747
}
4848

@@ -67,13 +67,24 @@ protected function getHeader(): string
6767
protected function runCommand(InputInterface $input, OutputInterface $output)
6868
{
6969
$appName = $input->getArgument('app-name');
70-
$index = $input->getArgument('index');
70+
$indexName = $input->getArgument('index-name');
71+
$indexArray = $this
72+
->repositoryBucket
73+
->getConfiguration()[$appName]['indices'] ?? [];
74+
75+
if (!isset($indexArray[$indexName])) {
76+
$this->printInfoMessage(
77+
$output,
78+
$this->getHeader(),
79+
'Index does not exist with this name.'
80+
);
81+
}
7182

7283
try {
7384
$this
7485
->repositoryBucket
7586
->findRepository($appName)
76-
->deleteIndex(IndexUUID::createById($index));
87+
->deleteIndex(IndexUUID::createById($indexArray[$indexName]));
7788
} catch (ResourceNotAvailableException $exception) {
7889
$this->printInfoMessage(
7990
$output,

0 commit comments

Comments
 (0)