Skip to content

Commit 4223734

Browse files
authored
Merge pull request #246 from taosdata/enh/TD-26237-modify-enterprise-version-check
ref: enterprise version check sucess if match one situation
2 parents 83ae42e + 824e634 commit 4223734

File tree

3 files changed

+44
-53
lines changed

3 files changed

+44
-53
lines changed

taos-optin/src/lib.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use std::{
77
use once_cell::sync::OnceCell;
88
use raw::{ApiEntry, BlockState, RawRes, RawTaos};
99

10-
use taos_query::prelude::{Field, Precision, RawBlock, RawMeta, RawResult};
10+
use taos_query::{prelude::{Field, Precision, RawBlock, RawMeta, RawResult, Code}, RawError};
1111

1212
const MAX_CONNECT_RETRIES: u8 = 16;
1313

@@ -397,26 +397,25 @@ impl taos_query::TBuilder for TaosBuilder {
397397
fn is_enterprise_edition(&self) -> RawResult<bool> {
398398
let taos = self.inner_connection()?;
399399
use taos_query::prelude::sync::Queryable;
400-
let grant: Option<(String, bool)> = Queryable::query_one(
400+
let grant: RawResult<Option<(String, bool)>> = Queryable::query_one(
401401
taos,
402402
"select version, (expire_time < now) as valid from information_schema.ins_cluster",
403-
)
404-
.unwrap_or_default();
403+
);
405404

406-
if let Some((edition, expired)) = grant {
405+
if let Ok(Some((edition, expired))) = grant {
407406
if expired {
408-
return Ok(false);
407+
return Err(RawError::new(Code::FAILED, r#"Enterprise version expired. Please get a new license to activate."#));
409408
}
410409
return match edition.as_str() {
411410
"cloud" | "official" | "trial" => Ok(true),
412411
_ => Ok(false),
413412
};
414413
}
415414

416-
let grant: Option<(String, (), String)> =
417-
Queryable::query_one(taos, "show grants").unwrap_or_default();
415+
let grant: RawResult<Option<(String, (), String)>> =
416+
Queryable::query_one(taos, "show grants");
418417

419-
if let Some((edition, _, expired)) = grant {
418+
if let Ok(Some((edition, _, expired))) = grant {
420419
match (edition.trim(), expired.trim()) {
421420
("cloud" | "official" | "trial", "false") => Ok(true),
422421
_ => Ok(false),
@@ -517,28 +516,26 @@ impl taos_query::AsyncTBuilder for TaosBuilder {
517516
async fn is_enterprise_edition(&self) -> RawResult<bool> {
518517
let taos = self.inner_connection()?;
519518
use taos_query::prelude::AsyncQueryable;
520-
let grant: Option<(String, bool)> = AsyncQueryable::query_one(
519+
let grant: RawResult<Option<(String, bool)>> = AsyncQueryable::query_one(
521520
taos,
522521
"select version, (expire_time < now) as valid from information_schema.ins_cluster",
523522
)
524-
.await
525-
.unwrap_or_default();
523+
.await;
526524

527-
if let Some((edition, expired)) = grant {
525+
if let Ok(Some((edition, expired))) = grant {
528526
if expired {
529-
return Ok(false);
527+
return Err(RawError::new(Code::FAILED, r#"Enterprise version expired. Please get a new license to activate."#));
530528
}
531529
return match edition.as_str() {
532530
"cloud" | "official" | "trial" => Ok(true),
533531
_ => Ok(false),
534532
};
535533
}
536534

537-
let grant: Option<(String, (), String)> = AsyncQueryable::query_one(taos, "show grants")
538-
.await
539-
.unwrap_or_default();
535+
let grant: RawResult<Option<(String, (), String)>> = AsyncQueryable::query_one(taos, "show grants")
536+
.await;
540537

541-
if let Some((edition, _, expired)) = grant {
538+
if let Ok(Some((edition, _, expired))) = grant {
542539
match (edition.trim(), expired.trim()) {
543540
("cloud" | "official" | "trial", "false") => Ok(true),
544541
_ => Ok(false),

taos-sys/src/lib.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -366,26 +366,25 @@ impl taos_query::TBuilder for TaosBuilder {
366366
fn is_enterprise_edition(&self) -> RawResult<bool> {
367367
let taos = self.inner_connection()?;
368368
use taos_query::prelude::sync::Queryable;
369-
let grant: Option<(String, bool)> = Queryable::query_one(
369+
let grant: RawResult<Option<(String, bool)>> = Queryable::query_one(
370370
taos,
371371
"select version, (expire_time < now) as valid from information_schema.ins_cluster",
372-
)
373-
.unwrap_or_default();
372+
);
374373

375-
if let Some((edition, expired)) = grant {
374+
if let Ok(Some((edition, expired))) = grant {
376375
if expired {
377-
return Ok(false);
376+
return Err(RawError::new(Code::FAILED, r#"Enterprise version expired. Please get a new license to activate."#));
378377
}
379378
return match edition.as_str() {
380379
"cloud" | "official" | "trial" => Ok(true),
381380
_ => Ok(false),
382381
};
383382
}
384383

385-
let grant: Option<(String, (), String)> =
386-
Queryable::query_one(taos, "show grants").unwrap_or_default();
384+
let grant: RawResult<Option<(String, (), String)>> =
385+
Queryable::query_one(taos, "show grants");
387386

388-
if let Some((edition, _, expired)) = grant {
387+
if let Ok(Some((edition, _, expired))) = grant {
389388
match (edition.trim(), expired.trim()) {
390389
("cloud" | "official" | "trial", "false") => Ok(true),
391390
_ => Ok(false),
@@ -486,28 +485,26 @@ impl taos_query::AsyncTBuilder for TaosBuilder {
486485
async fn is_enterprise_edition(&self) -> RawResult<bool> {
487486
let taos = self.async_inner_connection().await?;
488487
use taos_query::prelude::AsyncQueryable;
489-
let grant: Option<(String, bool)> = AsyncQueryable::query_one(
488+
let grant: RawResult<Option<(String, bool)>> = AsyncQueryable::query_one(
490489
taos,
491490
"select version, (expire_time < now) as valid from information_schema.ins_cluster",
492491
)
493-
.await
494-
.unwrap_or_default();
492+
.await;
495493

496-
if let Some((edition, expired)) = grant {
494+
if let Ok(Some((edition, expired))) = grant {
497495
if expired {
498-
return Ok(false);
496+
return Err(RawError::new(Code::FAILED, r#"Enterprise version expired. Please get a new license to activate."#));
499497
}
500498
return match edition.as_str() {
501499
"cloud" | "official" | "trial" => Ok(true),
502500
_ => Ok(false),
503501
};
504502
}
505503

506-
let grant: Option<(String, (), String)> = AsyncQueryable::query_one(taos, "show grants")
507-
.await
508-
.unwrap_or_default();
504+
let grant: RawResult<Option<(String, (), String)>> = AsyncQueryable::query_one(taos, "show grants")
505+
.await;
509506

510-
if let Some((edition, _, expired)) = grant {
507+
if let Ok(Some((edition, _, expired))) = grant {
511508
match (edition.trim(), expired.trim()) {
512509
("cloud" | "official" | "trial", "false") => Ok(true),
513510
_ => Ok(false),

taos-ws/src/lib.rs

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use std::fmt::{Debug, Display};
44
use once_cell::sync::OnceCell;
55

66
use taos_query::prelude::Code;
7-
use taos_query::{DsnError, IntoDsn, RawResult};
7+
use taos_query::{DsnError, IntoDsn, RawResult, RawError};
88

99
pub mod stmt;
1010
pub use stmt::Stmt;
@@ -128,26 +128,25 @@ impl taos_query::TBuilder for TaosBuilder {
128128
let taos = self.build()?;
129129

130130
use taos_query::prelude::sync::Queryable;
131-
let grant: Option<(String, bool)> = Queryable::query_one(
131+
let grant: RawResult<Option<(String, bool)>> = Queryable::query_one(
132132
&taos,
133133
"select version, (expire_time < now) from information_schema.ins_cluster",
134-
)
135-
.unwrap_or_default();
134+
);
136135

137-
if let Some((edition, expired)) = grant {
136+
if let Ok(Some((edition, expired))) = grant {
138137
if expired {
139-
return Ok(false);
138+
return Err(RawError::new(Code::FAILED, r#"Enterprise version expired. Please get a new license to activate."#));
140139
}
141140
return match edition.trim() {
142141
"cloud" | "official" | "trial" => Ok(true),
143142
_ => Ok(false),
144143
};
145144
}
146145

147-
let grant: Option<(String, (), String)> =
148-
Queryable::query_one(&taos, "show grants").unwrap_or_default();
146+
let grant: RawResult<Option<(String, (), String)>> =
147+
Queryable::query_one(&taos, "show grants");
149148

150-
if let Some((edition, _, expired)) = grant {
149+
if let Ok(Some((edition, _, expired))) = grant {
151150
match (edition.trim(), expired.trim()) {
152151
("cloud" | "official" | "trial", "false") => Ok(true),
153152
_ => Ok(false),
@@ -216,28 +215,26 @@ impl taos_query::AsyncTBuilder for TaosBuilder {
216215
false => (),
217216
}
218217

219-
let grant: Option<(String, bool)> = AsyncQueryable::query_one(
218+
let grant: RawResult<Option<(String, bool)>> = AsyncQueryable::query_one(
220219
&taos,
221220
"select version, (expire_time < now) from information_schema.ins_cluster",
222221
)
223-
.await
224-
.unwrap_or_default();
222+
.await;
225223

226-
if let Some((edition, expired)) = grant {
224+
if let Ok(Some((edition, expired))) = grant {
227225
if expired {
228-
return Ok(false);
226+
return Err(RawError::new(Code::FAILED, r#"Enterprise version expired. Please get a new license to activate."#));
229227
}
230228
return match edition.trim() {
231229
"cloud" | "official" | "trial" => Ok(true),
232230
_ => Ok(false),
233231
};
234232
}
235233

236-
let grant: Option<(String, (), String)> = AsyncQueryable::query_one(&taos, "show grants")
237-
.await
238-
.unwrap_or_default();
234+
let grant: RawResult<Option<(String, (), String)>> = AsyncQueryable::query_one(&taos, "show grants")
235+
.await;
239236

240-
if let Some((edition, _, expired)) = grant {
237+
if let Ok(Some((edition, _, expired))) = grant {
241238
match (edition.trim(), expired.trim()) {
242239
("cloud" | "official" | "trial", "false") => Ok(true),
243240
_ => Ok(false),

0 commit comments

Comments
 (0)