Skip to content

Commit 108ab9a

Browse files
authored
YDB CLI. Use CLI settings parameter instead of compile flag to disable updates (#14451)
1 parent 8dba86e commit 108ab9a

File tree

12 files changed

+51
-71
lines changed

12 files changed

+51
-71
lines changed

ydb/apps/ydb/commands/ya.make

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,11 @@
11
LIBRARY(commands)
22

33
SRCS(
4-
ydb_cloud_root.cpp
4+
ydb_root.cpp
5+
ydb_update.cpp
56
ydb_version.cpp
67
)
78

8-
IF (YDB_CERTIFIED)
9-
CFLAGS(
10-
-DDISABLE_UPDATE
11-
)
12-
ELSE()
13-
SRCS(
14-
ydb_update.cpp
15-
)
16-
ENDIF ()
17-
189
PEERDIR(
1910
ydb/public/sdk/cpp/src/client/iam
2011
ydb/public/lib/ydb_cli/commands

ydb/apps/ydb/commands/ydb_cloud_root.cpp renamed to ydb/apps/ydb/commands/ydb_root.cpp

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
1-
#include "ydb_cloud_root.h"
1+
#include "ydb_root.h"
2+
#include "ydb_update.h"
23
#include "ydb_version.h"
34

45
#include <ydb-cpp-sdk/client/iam/iam.h>
56
#include <ydb-cpp-sdk/client/types/credentials/oauth2_token_exchange/from_file.h>
67

7-
#ifndef DISABLE_UPDATE
8-
#include "ydb_update.h"
98
#include <ydb/public/lib/ydb_cli/common/ydb_updater.h>
10-
#endif
119

1210
#include <filesystem>
1311

@@ -56,12 +54,12 @@ void TClientCommandRoot::SetCredentialsGetter(TConfig& config) {
5654
};
5755
}
5856

59-
TYCloudClientCommandRoot::TYCloudClientCommandRoot(const TString& name, const TClientSettings& settings)
57+
TYdbClientCommandRoot::TYdbClientCommandRoot(const TString& name, const TClientSettings& settings)
6058
: TClientCommandRoot(name, settings)
6159
{
62-
#ifndef DISABLE_UPDATE
63-
AddCommand(std::make_unique<TCommandUpdate>());
64-
#endif
60+
if (settings.StorageUrl.has_value()) {
61+
AddCommand(std::make_unique<TCommandUpdate>());
62+
}
6563
AddCommand(std::make_unique<TCommandVersion>());
6664
}
6765

@@ -76,17 +74,16 @@ namespace {
7674
}
7775
}
7876

79-
void TYCloudClientCommandRoot::Config(TConfig& config) {
77+
void TYdbClientCommandRoot::Config(TConfig& config) {
8078
TClientCommandRoot::Config(config);
8179

8280
NLastGetopt::TOpts& opts = *config.Opts;
8381
RemoveOption(opts, "svnrevision");
8482
}
8583

86-
int TYCloudClientCommandRoot::Run(TConfig& config) {
87-
#ifndef DISABLE_UPDATE
88-
if (config.NeedToCheckForUpdate) {
89-
TYdbUpdater updater;
84+
int TYdbClientCommandRoot::Run(TConfig& config) {
85+
if (config.StorageUrl.has_value() && config.NeedToCheckForUpdate) {
86+
TYdbUpdater updater(config.StorageUrl.value());
9087
if (config.ForceVersionCheck) {
9188
Cout << "Force checking if there is a newer version..." << Endl;
9289
}
@@ -101,12 +98,11 @@ int TYCloudClientCommandRoot::Run(TConfig& config) {
10198
<< colors.OldColor() << Endl;
10299
}
103100
}
104-
#endif
105101

106102
return TClientCommandRoot::Run(config);
107103
}
108104

109-
int NewYCloudClient(int argc, char** argv) {
105+
int NewYdbClient(int argc, char** argv) {
110106
NYdb::NConsoleClient::TClientSettings settings;
111107
settings.EnableSsl = true;
112108
settings.UseAccessToken = true;
@@ -116,9 +112,10 @@ int NewYCloudClient(int argc, char** argv) {
116112
settings.UseOauth2TokenExchange = true;
117113
settings.UseExportToYt = false;
118114
settings.MentionUserAccount = false;
115+
settings.StorageUrl = "https://storage.yandexcloud.net/yandexcloud-ydb/release";
119116
settings.YdbDir = "ydb";
120117

121-
auto commandsRoot = MakeHolder<TYCloudClientCommandRoot>(std::filesystem::path(argv[0]).stem().string(), settings);
118+
auto commandsRoot = MakeHolder<TYdbClientCommandRoot>(std::filesystem::path(argv[0]).stem().string(), settings);
122119
commandsRoot->Opts.SetTitle("YDB client");
123120
TClientCommand::TConfig config(argc, argv);
124121
return commandsRoot->Process(config);

ydb/apps/ydb/commands/ydb_cloud_root.h renamed to ydb/apps/ydb/commands/ydb_root.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ class TClientCommandRoot : public TClientCommandRootCommon {
1414
void SetCredentialsGetter(TConfig& config) override;
1515
};
1616

17-
class TYCloudClientCommandRoot : public TClientCommandRoot {
17+
class TYdbClientCommandRoot : public TClientCommandRoot {
1818
public:
19-
TYCloudClientCommandRoot(const TString& name, const TClientSettings& settings);
19+
TYdbClientCommandRoot(const TString& name, const TClientSettings& settings);
2020
void Config(TConfig& config) override;
2121
int Run(TConfig& config) override;
2222
};
2323

24-
int NewYCloudClient(int argc, char** argv);
24+
int NewYdbClient(int argc, char** argv);
2525

2626
}
2727
}

ydb/apps/ydb/commands/ydb_update.cpp

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,7 @@ void TCommandUpdate::Config(TConfig& config) {
2020
}
2121

2222
int TCommandUpdate::Run(TConfig& config) {
23-
Y_UNUSED(config);
24-
25-
26-
TYdbUpdater updater;
23+
TYdbUpdater updater(config.StorageUrl.value());
2724
return updater.Update(ForceUpdate);
2825
}
2926

ydb/apps/ydb/commands/ydb_version.cpp

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
#include "ydb_version.h"
22

3-
#ifndef DISABLE_UPDATE
4-
#include <ydb/public/lib/ydb_cli/common/ydb_updater.h>
5-
#endif
3+
#include <ydb/public/lib/ydb_cli/common/ydb_updater.h>
64

75
#include <library/cpp/resource/resource.h>
86
#include <util/string/strip.h>
@@ -24,8 +22,11 @@ void TCommandVersion::Config(TConfig& config) {
2422

2523
config.Opts->AddLongOption("semantic", "Print semantic version only")
2624
.StoreTrue(&Semantic);
25+
26+
if (!config.StorageUrl.has_value()) {
27+
return;
28+
}
2729

28-
#ifndef DISABLE_UPDATE
2930
config.Opts->AddLongOption("check", "Force to check latest version available")
3031
.StoreTrue(&config.ForceVersionCheck);
3132
config.Opts->AddLongOption("disable-checks", "Disable version checks. CLI will not check whether there is a newer version available")
@@ -39,8 +40,6 @@ void TCommandVersion::Config(TConfig& config) {
3940
config.Opts->MutuallyExclusive("enable-checks", "semantic");
4041
config.Opts->MutuallyExclusive("enable-checks", "check");
4142
config.Opts->MutuallyExclusive("check", "semantic");
42-
#endif
43-
4443
}
4544

4645
void TCommandVersion::Parse(TConfig& config) {
@@ -52,20 +51,20 @@ void TCommandVersion::Parse(TConfig& config) {
5251
int TCommandVersion::Run(TConfig& config) {
5352
Y_UNUSED(config);
5453

55-
#ifndef DISABLE_UPDATE
56-
if (EnableChecks) {
57-
TYdbUpdater updater;
58-
updater.SetCheckVersion(true);
59-
Cout << "Latest version checks enabled" << Endl;
60-
return EXIT_SUCCESS;
61-
}
62-
if (DisableChecks) {
63-
TYdbUpdater updater;
64-
updater.SetCheckVersion(false);
65-
Cout << "Latest version checks disabled" << Endl;
66-
return EXIT_SUCCESS;
54+
if (config.StorageUrl.has_value()) {
55+
if (EnableChecks) {
56+
TYdbUpdater updater(config.StorageUrl.value());
57+
updater.SetCheckVersion(true);
58+
Cout << "Latest version checks enabled" << Endl;
59+
return EXIT_SUCCESS;
60+
}
61+
if (DisableChecks) {
62+
TYdbUpdater updater(config.StorageUrl.value());
63+
updater.SetCheckVersion(false);
64+
Cout << "Latest version checks disabled" << Endl;
65+
return EXIT_SUCCESS;
66+
}
6767
}
68-
#endif
6968

7069
if (!Semantic) {
7170
Cout << "YDB CLI ";

ydb/apps/ydb/main.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include <ydb/apps/ydb/commands/ydb_cloud_root.h>
1+
#include <ydb/apps/ydb/commands/ydb_root.h>
22
#include <ydb/public/lib/ydb_cli/commands/ydb_service_topic.h>
33

44
TVector<NYdb::NTopic::ECodec> NYdb::NConsoleClient::InitAllowedCodecs() {
@@ -11,7 +11,7 @@ TVector<NYdb::NTopic::ECodec> NYdb::NConsoleClient::InitAllowedCodecs() {
1111

1212
int main(int argc, char **argv) {
1313
try {
14-
return NYdb::NConsoleClient::NewYCloudClient(argc, argv);
14+
return NYdb::NConsoleClient::NewYdbClient(argc, argv);
1515
}
1616
catch (const NYdb::NConsoleClient::TMisuseWithHelpException& e) {
1717
// command help is already printed. Just exit(1)

ydb/public/lib/ydb_cli/commands/ydb_root_common.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ void TClientCommandRootCommon::FillConfig(TConfig& config) {
8888
config.UseStaticCredentials = Settings.UseStaticCredentials.GetRef();
8989
config.UseOauth2TokenExchange = Settings.UseOauth2TokenExchange.GetRef();
9090
config.UseExportToYt = Settings.UseExportToYt.GetRef();
91+
config.StorageUrl = Settings.StorageUrl;
9192
SetCredentialsGetter(config);
9293
}
9394

ydb/public/lib/ydb_cli/commands/ydb_root_common.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ struct TClientSettings {
2323
TMaybe<bool> UseExportToYt;
2424
// Whether to mention user account in --help command or not
2525
TMaybe<bool> MentionUserAccount;
26+
// A storage url to get latest YDB CLI version and to update from
27+
// If not set, than no updates nor latest version checks will be available
28+
std::optional<std::string> StorageUrl = std::nullopt;
2629
// Name of a directory in user home directory to save profile config
2730
TString YdbDir;
2831
};

ydb/public/lib/ydb_cli/common/command.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@ class TClientCommand {
148148
bool AllowEmptyAddress = false;
149149
bool OnlyExplicitProfile = false;
150150
bool AssumeYes = false;
151+
std::optional<std::string> StorageUrl = std::nullopt;
151152

152153
TCredentialsGetter CredentialsGetter;
153154
std::shared_ptr<ICredentialsProviderFactory> SingletonCredentialsProviderFactory = nullptr;

ydb/public/lib/ydb_cli/common/ya.make

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,19 +30,10 @@ SRCS(
3030
sys.cpp
3131
tabbed_table.cpp
3232
waiting_bar.cpp
33+
ydb_updater.cpp
3334
yt.cpp
3435
)
3536

36-
IF (YDB_CERTIFIED)
37-
CFLAGS(
38-
-DDISABLE_UPDATE
39-
)
40-
ELSE()
41-
SRCS(
42-
ydb_updater.cpp
43-
)
44-
ENDIF ()
45-
4637
PEERDIR(
4738
contrib/libs/aws-sdk-cpp/aws-cpp-sdk-s3
4839
library/cpp/config

0 commit comments

Comments
 (0)