aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorpnv1 <pnv@ydb.tech>2023-04-27 10:12:42 +0300
committerpnv1 <pnv@ydb.tech>2023-04-27 10:12:42 +0300
commit97ff996dcb6497c6c672826d252793899e8a478f (patch)
treed21257d2e18c5a8834b8c4d3f508ba65dc9cfa41
parentba1e7fcd36aca1f47d0ca457071e5373d659dc75 (diff)
downloadydb-97ff996dcb6497c6c672826d252793899e8a478f.tar.gz
Add object type to ydb scheme describe
-rw-r--r--ydb/docs/en/core/reference/ydb-cli/commands/_includes/scheme-describe.md2
-rw-r--r--ydb/docs/ru/core/reference/ydb-cli/commands/_includes/scheme-describe.md2
-rw-r--r--ydb/public/lib/ydb_cli/commands/ydb_service_scheme.cpp57
-rw-r--r--ydb/public/lib/ydb_cli/commands/ydb_service_scheme.h19
4 files changed, 49 insertions, 31 deletions
diff --git a/ydb/docs/en/core/reference/ydb-cli/commands/_includes/scheme-describe.md b/ydb/docs/en/core/reference/ydb-cli/commands/_includes/scheme-describe.md
index 90843e2db9..34b952f68c 100644
--- a/ydb/docs/en/core/reference/ydb-cli/commands/_includes/scheme-describe.md
+++ b/ydb/docs/en/core/reference/ydb-cli/commands/_includes/scheme-describe.md
@@ -9,6 +9,8 @@ Get information about a schema object:
Result:
```text
+<table> episodes
+
┌────────────┬─────────┬────────┬─────┐
| Name | Type | Family | Key |
├────────────┼─────────┼────────┼─────┤
diff --git a/ydb/docs/ru/core/reference/ydb-cli/commands/_includes/scheme-describe.md b/ydb/docs/ru/core/reference/ydb-cli/commands/_includes/scheme-describe.md
index 6b051d5700..dfb36e1c16 100644
--- a/ydb/docs/ru/core/reference/ydb-cli/commands/_includes/scheme-describe.md
+++ b/ydb/docs/ru/core/reference/ydb-cli/commands/_includes/scheme-describe.md
@@ -9,6 +9,8 @@
Результат:
```text
+<table> episodes
+
┌────────────┬─────────┬────────┬─────┐
| Name | Type | Family | Key |
├────────────┼─────────┼────────┼─────┤
diff --git a/ydb/public/lib/ydb_cli/commands/ydb_service_scheme.cpp b/ydb/public/lib/ydb_cli/commands/ydb_service_scheme.cpp
index d85e5dc82f..6c3d89107d 100644
--- a/ydb/public/lib/ydb_cli/commands/ydb_service_scheme.cpp
+++ b/ydb/public/lib/ydb_cli/commands/ydb_service_scheme.cpp
@@ -111,25 +111,17 @@ namespace {
Cout << "none" << Endl;
}
}
+}
- void PrintAllPermissions(
- const TString& owner,
- const TVector<NScheme::TPermissions>& permissions,
- const TVector<NScheme::TPermissions>& effectivePermissions
- ) {
- Cout << "Owner: " << owner << Endl << Endl << "Permissions: " << Endl;
- PrintPermissions(permissions);
- Cout << Endl << "Effective permissions: " << Endl;
- PrintPermissions(effectivePermissions);
- }
-
- void PrintEntryVerbose(const NScheme::TSchemeEntry& entry, bool permissions) {
- Cout << "<" << EntryTypeToString(entry.Type) << "> " << entry.Name << Endl;
- if (permissions) {
- Cout << Endl;
- PrintAllPermissions(entry.Owner, entry.Permissions, entry.EffectivePermissions);
- }
- }
+void PrintAllPermissions(
+ const TString& owner,
+ const TVector<NScheme::TPermissions>& permissions,
+ const TVector<NScheme::TPermissions>& effectivePermissions
+) {
+ Cout << "Owner: " << owner << Endl << Endl << "Permissions: " << Endl;
+ PrintPermissions(permissions);
+ Cout << Endl << "Effective permissions: " << Endl;
+ PrintPermissions(effectivePermissions);
}
TCommandDescribe::TCommandDescribe()
@@ -174,6 +166,7 @@ int TCommandDescribe::Run(TConfig& config) {
int TCommandDescribe::PrintPathResponse(TDriver& driver, const NScheme::TDescribePathResult& result) {
NScheme::TSchemeEntry entry = result.GetEntry();
+ Cout << "<" << EntryTypeToString(entry.Type) << "> " << entry.Name << Endl;
switch (entry.Type) {
case NScheme::ESchemeEntryType::Table:
return DescribeTable(driver);
@@ -185,9 +178,17 @@ int TCommandDescribe::PrintPathResponse(TDriver& driver, const NScheme::TDescrib
case NScheme::ESchemeEntryType::CoordinationNode:
return DescribeCoordinationNode(driver);
default:
- WarnAboutTableOptions();
- PrintEntryVerbose(entry, ShowPermissions);
+ return DescribeEntryDefault(entry);
+ }
+ return EXIT_SUCCESS;
+}
+
+int TCommandDescribe::DescribeEntryDefault(NScheme::TSchemeEntry entry) {
+ if (ShowPermissions) {
+ Cout << Endl;
+ PrintAllPermissions(entry.Owner, entry.Permissions, entry.EffectivePermissions);
}
+ WarnAboutTableOptions();
return EXIT_SUCCESS;
}
@@ -278,6 +279,8 @@ int TCommandDescribe::PrintTopicResponsePretty(const NYdb::NTopic::TTopicDescrip
}
PrintTopicConsumers(description.GetConsumers());
+ PrintPermissionsIfNeeded(description);
+
if (ShowStats) {
PrintStatistics(description);
}
@@ -386,7 +389,7 @@ int TCommandDescribe::PrintCoordinationNodeResponse(const NYdb::NCoordination::T
}
int TCommandDescribe::PrintCoordinationNodeResponsePretty(const NYdb::NCoordination::TNodeDescription& result) const {
- Cout << "AttachConsistencyMode: " << result.GetAttachConsistencyMode() << Endl;
+ Cout << Endl << "AttachConsistencyMode: " << result.GetAttachConsistencyMode() << Endl;
Cout << "ReadConsistencyMode: " << result.GetReadConsistencyMode() << Endl;
if (result.GetSessionGracePeriod().Defined()) {
Cout << "SessionGracePeriod: " << result.GetSessionGracePeriod() << Endl;
@@ -427,6 +430,7 @@ namespace {
if (!tableDescription.GetTableColumns().size()) {
return;
}
+ Cerr << Endl;
TPrettyTable table({ "Name", "Type", "Family", "Key" }, TPrettyTableConfig().WithoutRowDelimiters());
const TVector<TString>& keyColumns = tableDescription.GetPrimaryKeyColumns();
@@ -777,16 +781,7 @@ void TCommandDescribe::PrintResponsePretty(const NTable::TTableDescription& tabl
<< (tableDescription.GetKeyBloomFilter().GetRef() ? "true" : "false") << Endl;
}
PrintReadReplicasSettings(tableDescription);
- if (ShowPermissions) {
- if (tableDescription.GetColumns().size()) {
- Cout << Endl;
- }
- PrintAllPermissions(
- tableDescription.GetOwner(),
- tableDescription.GetPermissions(),
- tableDescription.GetEffectivePermissions()
- );
- }
+ PrintPermissionsIfNeeded(tableDescription);
if (ShowStats) {
PrintStatistics(tableDescription);
}
diff --git a/ydb/public/lib/ydb_cli/commands/ydb_service_scheme.h b/ydb/public/lib/ydb_cli/commands/ydb_service_scheme.h
index a86fc59489..f7be849879 100644
--- a/ydb/public/lib/ydb_cli/commands/ydb_service_scheme.h
+++ b/ydb/public/lib/ydb_cli/commands/ydb_service_scheme.h
@@ -38,6 +38,12 @@ private:
TMaybe<ERecursiveRemovePrompt> Prompt;
};
+void PrintAllPermissions(
+ const TString& owner,
+ const TVector<NScheme::TPermissions>& permissions,
+ const TVector<NScheme::TPermissions>& effectivePermissions
+);
+
class TCommandDescribe : public TYdbOperationCommand, public TCommandWithPath, public TCommandWithFormat {
public:
TCommandDescribe();
@@ -47,6 +53,7 @@ public:
private:
int PrintPathResponse(TDriver& driver, const NScheme::TDescribePathResult& result);
+ int DescribeEntryDefault(NScheme::TSchemeEntry entry);
int DescribeTable(TDriver& driver);
int DescribeColumnTable(TDriver& driver);
int PrintTableResponse(NTable::TDescribeTableResult& result);
@@ -64,6 +71,18 @@ private:
int PrintCoordinationNodeResponsePretty(const NYdb::NCoordination::TNodeDescription& result) const;
int PrintCoordinationNodeResponseProtoJsonBase64(const NYdb::NCoordination::TNodeDescription& result) const;
+ template<typename TDescriptionType>
+ void PrintPermissionsIfNeeded(const TDescriptionType& description) {
+ if (ShowPermissions) {
+ Cout << Endl;
+ PrintAllPermissions(
+ description.GetOwner(),
+ description.GetPermissions(),
+ description.GetEffectivePermissions()
+ );
+ }
+ }
+
// Common options
bool ShowPermissions = false;
// Table options