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

Commit 4a1c181

Browse files
authored
Merge pull request #44 from apisearch-io/fix/fixed-token-commands
Fixed some tokens commands
2 parents 7aa7b42 + b3ad165 commit 4a1c181

File tree

4 files changed

+66
-64
lines changed

4 files changed

+66
-64
lines changed

.php_cs.cache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"php":"7.1.23-2+ubuntu16.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":{"Tests\/Functional\/ProductBothTransformer.php":3061253314,"Tests\/Functional\/ProductReadTransformer.php":1666987200,"Tests\/Functional\/ApisearchBundleFunctionalTest.php":1130132530,"Tests\/Functional\/ProductWriteTransformer.php":4090808924,"Tests\/Functional\/Command\/IndexCommandTest.php":673234498,"Tests\/Functional\/Command\/PrintIndicesCommandTest.php":481741707,"Tests\/Functional\/Command\/QueryCommandTest.php":2580406218,"Tests\/Functional\/Command\/AddDeleteTokensCommandTest.php":3415234775,"Tests\/Functional\/DependencyInjection\/EnableCommandsTest.php":1149363544,"Tests\/Functional\/DependencyInjection\/CompilerPass\/InMemoryRepositoryCompilerPassTest.php":3052848166,"Tests\/Functional\/DependencyInjection\/CompilerPass\/TransformersCompilerPassTest.php":1388027657,"Tests\/Functional\/DependencyInjection\/CompilerPass\/HttpRepositoryCompilerPassTest.php":2500445244,"Tests\/Functional\/DependencyInjection\/DisableCommandsTest.php":2956180423,"Tests\/Functional\/DependencyInjection\/ApisearchConfigurationTest.php":271608124,"Translator\/AggregationTranslator.php":4238166597,"ApisearchBundle.php":3640212495,"Twig\/MethodAccessorExtension.php":2939807874,"Twig\/AggregationTranslationExtension.php":2415810000,"Twig\/UrlBuilderExtension.php":2201893333,"Command\/ImportIndexCommand.php":3461230433,"Command\/CreateIndexCommand.php":3585751415,"Command\/ApisearchFormattedCommand.php":1111995920,"Command\/ResetIndexCommand.php":3426927232,"Command\/DeleteIndexCommand.php":1350714493,"Command\/ApisearchCommand.php":1457306061,"Command\/WithAppRepositoryBucketCommand.php":2197592132,"Command\/PrintIndicesCommand.php":2224987197,"Command\/DeleteTokensCommand.php":290859330,"Command\/AddTokenCommand.php":3261359949,"Command\/PrintTokensCommand.php":2242601131,"Command\/ExportIndexCommand.php":1133721139,"Command\/ConfigureIndexCommand.php":2627529992,"Command\/WithRepositoryBucketCommand.php":3434324818,"Command\/DeleteTokenCommand.php":121828308,"Command\/QueryCommand.php":362290438,"DependencyInjection\/CompilerPass\/WriteTransformerCompilerPass.php":2530587380,"DependencyInjection\/CompilerPass\/ExporterCompilerPass.php":857546720,"DependencyInjection\/CompilerPass\/RepositoryCompilerPass.php":4244359397,"DependencyInjection\/CompilerPass\/ReadTransformerCompilerPass.php":3948110591,"DependencyInjection\/ApisearchConfiguration.php":1136730770,"DependencyInjection\/ApisearchExtension.php":112225700}}
1+
{"php":"7.1.23-2+ubuntu16.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":{"Tests\/Functional\/ProductBothTransformer.php":3061253314,"Tests\/Functional\/ProductReadTransformer.php":1666987200,"Tests\/Functional\/ApisearchBundleFunctionalTest.php":1130132530,"Tests\/Functional\/ProductWriteTransformer.php":4090808924,"Tests\/Functional\/Command\/IndexCommandTest.php":673234498,"Tests\/Functional\/Command\/PrintIndicesCommandTest.php":481741707,"Tests\/Functional\/Command\/QueryCommandTest.php":2580406218,"Tests\/Functional\/Command\/AddDeleteTokensCommandTest.php":3415234775,"Tests\/Functional\/DependencyInjection\/EnableCommandsTest.php":1149363544,"Tests\/Functional\/DependencyInjection\/CompilerPass\/InMemoryRepositoryCompilerPassTest.php":3052848166,"Tests\/Functional\/DependencyInjection\/CompilerPass\/TransformersCompilerPassTest.php":1388027657,"Tests\/Functional\/DependencyInjection\/CompilerPass\/HttpRepositoryCompilerPassTest.php":2500445244,"Tests\/Functional\/DependencyInjection\/DisableCommandsTest.php":2956180423,"Tests\/Functional\/DependencyInjection\/ApisearchConfigurationTest.php":271608124,"Translator\/AggregationTranslator.php":4238166597,"ApisearchBundle.php":3640212495,"Twig\/MethodAccessorExtension.php":2939807874,"Twig\/AggregationTranslationExtension.php":2415810000,"Twig\/UrlBuilderExtension.php":2201893333,"Command\/ImportIndexCommand.php":3461230433,"Command\/CreateIndexCommand.php":3585751415,"Command\/ApisearchFormattedCommand.php":1111995920,"Command\/ResetIndexCommand.php":3426927232,"Command\/DeleteIndexCommand.php":1350714493,"Command\/ApisearchCommand.php":1457306061,"Command\/WithAppRepositoryBucketCommand.php":2197592132,"Command\/PrintIndicesCommand.php":2224987197,"Command\/DeleteTokensCommand.php":290859330,"Command\/AddTokenCommand.php":684681072,"Command\/PrintTokensCommand.php":1079623314,"Command\/ExportIndexCommand.php":1133721139,"Command\/ConfigureIndexCommand.php":2627529992,"Command\/WithRepositoryBucketCommand.php":3434324818,"Command\/DeleteTokenCommand.php":121828308,"Command\/QueryCommand.php":362290438,"DependencyInjection\/CompilerPass\/WriteTransformerCompilerPass.php":2530587380,"DependencyInjection\/CompilerPass\/ExporterCompilerPass.php":857546720,"DependencyInjection\/CompilerPass\/RepositoryCompilerPass.php":4244359397,"DependencyInjection\/CompilerPass\/ReadTransformerCompilerPass.php":3948110591,"DependencyInjection\/ApisearchConfiguration.php":1136730770,"DependencyInjection\/ApisearchExtension.php":112225700}}

Command/AddTokenCommand.php

Lines changed: 25 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,6 @@ protected function configure()
5353
'Indices',
5454
[]
5555
)
56-
->addOption(
57-
'http-referrer',
58-
null,
59-
InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL,
60-
'Http referrers',
61-
[]
62-
)
6356
->addOption(
6457
'endpoint',
6558
null,
@@ -74,20 +67,6 @@ protected function configure()
7467
'Plugins',
7568
[]
7669
)
77-
->addOption(
78-
'seconds-valid',
79-
null,
80-
InputOption::VALUE_OPTIONAL,
81-
'Seconds valid',
82-
Token::INFINITE_DURATION
83-
)
84-
->addOption(
85-
'max-hits-per-query',
86-
null,
87-
InputOption::VALUE_OPTIONAL,
88-
'Maximum hits per query',
89-
Token::INFINITE_HITS_PER_QUERY
90-
)
9170
->addOption(
9271
'ttl',
9372
null,
@@ -97,34 +76,6 @@ protected function configure()
9776
);
9877
}
9978

100-
/**
101-
* Dispatch domain event.
102-
*
103-
* @return string
104-
*/
105-
protected static function getHeader(): string
106-
{
107-
return 'Add token';
108-
}
109-
110-
/**
111-
* Get success message.
112-
*
113-
* @param InputInterface $input
114-
* @param mixed $result
115-
*
116-
* @return string
117-
*/
118-
protected static function getSuccessMessage(
119-
InputInterface $input,
120-
$result
121-
): string {
122-
return sprintf(
123-
'Token with UUID <strong>%s</strong> added properly',
124-
$input->getArgument('uuid')
125-
);
126-
}
127-
12879
/**
12980
* Dispatch domain event.
13081
*
@@ -145,13 +96,35 @@ protected function runCommand(InputInterface $input, OutputInterface $output)
14596
TokenUUID::createById($input->getArgument('uuid')),
14697
$appUUID,
14798
$indices,
148-
$input->getOption('http-referrer'),
14999
$endpoints,
150100
$input->getOption('plugin'),
151-
(int) $input->getOption('seconds-valid'),
152-
(int) $input->getOption('max-hits-per-query'),
153101
(int) $input->getOption('ttl')
154102
)
155103
);
156104
}
105+
106+
/**
107+
* Dispatch domain event.
108+
*
109+
* @return string
110+
*/
111+
protected static function getHeader(): string
112+
{
113+
return 'Add token';
114+
}
115+
116+
/**
117+
* Get success message.
118+
*
119+
* @param InputInterface $input
120+
* @param mixed $result
121+
*
122+
* @return string
123+
*/
124+
protected static function getSuccessMessage(
125+
InputInterface $input,
126+
$result
127+
): string {
128+
return 'Token added properly';
129+
}
157130
}

Command/PrintTokensCommand.php

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
use Symfony\Component\Console\Helper\Table;
2121
use Symfony\Component\Console\Input\InputArgument;
2222
use Symfony\Component\Console\Input\InputInterface;
23+
use Symfony\Component\Console\Input\InputOption;
2324
use Symfony\Component\Console\Output\OutputInterface;
2425

2526
/**
@@ -38,6 +39,12 @@ protected function configure()
3839
'app-name',
3940
InputArgument::REQUIRED,
4041
'App name'
42+
)
43+
->addOption(
44+
'with-metadata',
45+
null,
46+
InputOption::VALUE_NONE,
47+
'Print metadata'
4148
);
4249
}
4350

@@ -61,7 +68,7 @@ protected function runCommand(InputInterface $input, OutputInterface $output)
6168
->repositoryBucket
6269
->getConfiguration()[$appName]['indices'] ?? [];
6370

64-
/**
71+
/*
6572
* @var Token[]
6673
*/
6774
foreach ($tokens as $token) {
@@ -98,22 +105,44 @@ public static function printTokens(
98105
OutputInterface $output,
99106
array $tokens
100107
) {
108+
$withMetadata = $input->getOption('with-metadata');
101109
$table = new Table($output);
102-
$table->setHeaders(['UUID', 'Indices', 'Seconds Valid', 'Max hits per query', 'HTTP Referrers', 'endpoints', 'plugins', 'ttl']);
110+
$headers = ['UUID', 'Indices', 'endpoints', 'plugins', 'ttl'];
111+
if ($withMetadata) {
112+
$headers[] = 'Metadata';
113+
}
114+
$table->setHeaders($headers);
115+
103116
foreach ($tokens as $token) {
104-
$table->addRow([
117+
$row = [
105118
$token->getTokenUUID()->composeUUID(),
106119
implode(', ', array_map(function (IndexUUID $index) {
107120
return $index->composeUUID();
108121
}, $token->getIndices())),
109-
$token->getSecondsValid(),
110-
$token->getMaxHitsPerQuery(),
111-
implode(', ', $token->getHttpReferrers()),
112122
implode(', ', $token->getEndpoints()),
113123
implode(', ', $token->getPlugins()),
114124
$token->getTtl(),
115-
]);
125+
];
126+
127+
if ($withMetadata) {
128+
$metadataRow = [];
129+
foreach ($token->getMetadata() as $metadataField => $metadataValue) {
130+
$metadataRow[] = sprintf("$metadataField = %s",
131+
is_bool($metadataValue)
132+
? $metadataValue ? 'true' : 'false'
133+
: (
134+
is_array($metadataValue)
135+
? implode(', ', $metadataValue)
136+
: (string) $metadataValue
137+
)
138+
);
139+
}
140+
$row[] = implode(PHP_EOL, $metadataRow);
141+
}
142+
143+
$table->addRow($row);
116144
}
145+
117146
$table->render();
118147
}
119148

composer.lock

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)