mirror of
https://github.com/timescale/timescaledb.git
synced 2025-05-15 18:13:18 +08:00
Add view displaying info about the current license
Currently the view displays the current edition, expiry date, and whether the license is expired. We're not displaying the license key itself in the view as it can get rather long, and get be read via SHOW. We also do not display the license's ID since that is for internal use.
This commit is contained in:
parent
47b5b7d553
commit
65894f08cf
@ -4,16 +4,19 @@
|
||||
-- at the top level directory of the TimescaleDB distribution.
|
||||
|
||||
CREATE OR REPLACE FUNCTION _timescaledb_internal.enterprise_enabled() RETURNS BOOLEAN
|
||||
AS '@MODULE_PATHNAME@', 'ts_enterprise_enabled' LANGUAGE C STABLE;
|
||||
AS '@MODULE_PATHNAME@', 'ts_enterprise_enabled' LANGUAGE C;
|
||||
|
||||
CREATE OR REPLACE FUNCTION _timescaledb_internal.current_license_key() RETURNS TEXT
|
||||
AS '@MODULE_PATHNAME@', 'ts_current_license_key' LANGUAGE C STABLE;
|
||||
AS '@MODULE_PATHNAME@', 'ts_current_license_key' LANGUAGE C;
|
||||
|
||||
CREATE OR REPLACE FUNCTION _timescaledb_internal.tsl_loaded() RETURNS BOOLEAN
|
||||
AS '@MODULE_PATHNAME@', 'ts_tsl_loaded' LANGUAGE C STABLE;
|
||||
AS '@MODULE_PATHNAME@', 'ts_tsl_loaded' LANGUAGE C;
|
||||
|
||||
CREATE OR REPLACE FUNCTION _timescaledb_internal.license_expiration_time() RETURNS TIMESTAMPTZ
|
||||
AS '@MODULE_PATHNAME@', 'ts_license_expiration_time' LANGUAGE C STABLE;
|
||||
AS '@MODULE_PATHNAME@', 'ts_license_expiration_time' LANGUAGE C;
|
||||
|
||||
CREATE OR REPLACE FUNCTION _timescaledb_internal.print_license_expiration_info() RETURNS VOID
|
||||
AS '@MODULE_PATHNAME@', 'ts_print_tsl_license_expiration_info' LANGUAGE C STABLE;
|
||||
AS '@MODULE_PATHNAME@', 'ts_print_tsl_license_expiration_info' LANGUAGE C;
|
||||
|
||||
CREATE OR REPLACE FUNCTION _timescaledb_internal.license_edition() RETURNS TEXT
|
||||
AS '@MODULE_PATHNAME@', 'ts_license_edition' LANGUAGE C;
|
||||
|
@ -25,6 +25,11 @@ CREATE OR REPLACE VIEW timescaledb_information.hypertable AS
|
||||
CASE WHEN has_schema_privilege(ht.schema_name,'USAGE') THEN format('%I.%I',ht.schema_name,ht.table_name) ELSE NULL END
|
||||
) size ON true;
|
||||
|
||||
CREATE OR REPLACE VIEW timescaledb_information.license AS
|
||||
SELECT _timescaledb_internal.license_edition() as edition,
|
||||
_timescaledb_internal.license_expiration_time() <= now() AS expired,
|
||||
_timescaledb_internal.license_expiration_time() AS expiration_time;
|
||||
|
||||
|
||||
GRANT USAGE ON SCHEMA timescaledb_information TO PUBLIC;
|
||||
GRANT SELECT ON ALL TABLES IN SCHEMA timescaledb_information TO PUBLIC;
|
||||
|
||||
|
@ -153,7 +153,7 @@ TSDLLEXPORT CrossModuleFunctions ts_cm_functions_default = {
|
||||
.enterprise_enabled_internal = error_no_default_fn_bool_void_enterprise,
|
||||
.check_tsl_loaded = error_no_default_fn_bool_void_community,
|
||||
.license_end_time = license_end_time_default_fn,
|
||||
.print_tsl_license_expiration_info_hook = error_no_default_fn_community,
|
||||
.print_tsl_license_expiration_info_hook = NULL,
|
||||
.module_shutdown_hook = NULL,
|
||||
.add_tsl_license_info_telemetry = add_telemetry_default,
|
||||
.bgw_policy_job_execute = bgw_policy_job_execute_default_fn,
|
||||
|
@ -18,6 +18,7 @@ TS_FUNCTION_INFO_V1(ts_current_license_key);
|
||||
TS_FUNCTION_INFO_V1(ts_tsl_loaded);
|
||||
TS_FUNCTION_INFO_V1(ts_print_tsl_license_expiration_info);
|
||||
TS_FUNCTION_INFO_V1(ts_license_expiration_time);
|
||||
TS_FUNCTION_INFO_V1(ts_license_edition);
|
||||
TS_FUNCTION_INFO_V1(ts_allow_downgrade_to_apache);
|
||||
|
||||
static bool downgrade_to_apache_enabled = false;
|
||||
@ -27,6 +28,10 @@ static PGFunction tsl_startup_fn = NULL;
|
||||
static bool can_load = false;
|
||||
static GucSource load_source = PGC_S_DEFAULT;
|
||||
|
||||
#define TS_LICENSE_APACHE_ONLY_PRINT_TEXT "apache"
|
||||
#define TS_LICENSE_COMMUNITY_PRINT_TEXT "community"
|
||||
#define TS_LICENSE_ENTERPRISE_PRINT_TEXT "enterprise"
|
||||
|
||||
/*
|
||||
* License Functions
|
||||
*
|
||||
@ -323,11 +328,35 @@ PGDLLEXPORT Datum
|
||||
ts_license_expiration_time(PG_FUNCTION_ARGS)
|
||||
{
|
||||
if (ts_cm_functions->print_tsl_license_expiration_info_hook == NULL)
|
||||
PG_RETURN_NULL();
|
||||
PG_RETURN_TIMESTAMPTZ(DT_NOEND);
|
||||
|
||||
PG_RETURN_TIMESTAMPTZ(ts_cm_functions->license_end_time());
|
||||
}
|
||||
|
||||
PGDLLEXPORT Datum
|
||||
ts_license_edition(PG_FUNCTION_ARGS)
|
||||
{
|
||||
char *edition = NULL;
|
||||
|
||||
switch (TS_CURRENT_LICENSE_TYPE())
|
||||
{
|
||||
case LICENSE_TYPE_APACHE_ONLY:
|
||||
edition = TS_LICENSE_APACHE_ONLY_PRINT_TEXT;
|
||||
break;
|
||||
case LICENSE_TYPE_COMMUNITY:
|
||||
edition = TS_LICENSE_COMMUNITY_PRINT_TEXT;
|
||||
break;
|
||||
case LICENSE_TYPE_ENTERPRISE:
|
||||
edition = TS_LICENSE_ENTERPRISE_PRINT_TEXT;
|
||||
break;
|
||||
default:
|
||||
elog(ERROR, "Invalid license key '%s'", ts_guc_license_key);
|
||||
pg_unreachable();
|
||||
}
|
||||
|
||||
PG_RETURN_TEXT_P(cstring_to_text(edition));
|
||||
}
|
||||
|
||||
/*
|
||||
* For testing purposes we occasionally need the ability to set the license to
|
||||
* Apache only. This function allows us to bypass the test that usually disables
|
||||
|
@ -40,13 +40,18 @@ typedef enum LicenseType
|
||||
#define TS_DEFAULT_LICENSE TS_COMMUNITY_LICENSE
|
||||
#endif
|
||||
|
||||
#define TS_LICENSE_TYPE(license) license[0]
|
||||
|
||||
#define TS_LICENSE_TYPE_IS_VALID(license) \
|
||||
(license[0] == LICENSE_TYPE_APACHE_ONLY || \
|
||||
license[0] == LICENSE_TYPE_COMMUNITY || \
|
||||
license[0] == LICENSE_TYPE_ENTERPRISE)
|
||||
(TS_LICENSE_TYPE(license) == LICENSE_TYPE_APACHE_ONLY || \
|
||||
TS_LICENSE_TYPE(license) == LICENSE_TYPE_COMMUNITY || \
|
||||
TS_LICENSE_TYPE(license) == LICENSE_TYPE_ENTERPRISE)
|
||||
|
||||
#define TS_LICENSE_IS_APACHE_ONLY(license) \
|
||||
(license[0] == LICENSE_TYPE_APACHE_ONLY)
|
||||
(TS_LICENSE_TYPE(license) == LICENSE_TYPE_APACHE_ONLY)
|
||||
|
||||
#define TS_CURRENT_LICENSE_TYPE() \
|
||||
TS_LICENSE_TYPE(ts_guc_license_key)
|
||||
|
||||
#define TS_CURRENT_LICENSE_IS_APACHE_ONLY() \
|
||||
TS_LICENSE_IS_APACHE_ONLY(ts_guc_license_key)
|
||||
|
@ -20,3 +20,17 @@ SELECT _timescaledb_internal.enterprise_enabled();
|
||||
f
|
||||
(1 row)
|
||||
|
||||
\unset ECHO
|
||||
SELECT allow_downgrade_to_apache();
|
||||
allow_downgrade_to_apache
|
||||
---------------------------
|
||||
|
||||
(1 row)
|
||||
|
||||
SET timescaledb.license_key='ApacheOnly';
|
||||
select * from timescaledb_information.license;
|
||||
edition | expired | expiration_time
|
||||
---------+---------+-----------------
|
||||
apache | f | infinity
|
||||
(1 row)
|
||||
|
||||
|
@ -489,9 +489,10 @@ WHERE refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass AND
|
||||
AND objid NOT IN (select unnest(extconfig) from pg_extension where extname='timescaledb');
|
||||
objid
|
||||
----------------------------------------------
|
||||
timescaledb_information.license
|
||||
timescaledb_information.hypertable
|
||||
_timescaledb_internal.bgw_policy_chunk_stats
|
||||
_timescaledb_internal.bgw_job_stat
|
||||
_timescaledb_catalog.tablespace_id_seq
|
||||
(4 rows)
|
||||
(5 rows)
|
||||
|
||||
|
@ -6,3 +6,16 @@
|
||||
SELECT _timescaledb_internal.current_license_key();
|
||||
SELECT _timescaledb_internal.tsl_loaded();
|
||||
SELECT _timescaledb_internal.enterprise_enabled();
|
||||
|
||||
\unset ECHO
|
||||
\o /dev/null
|
||||
\ir include/test_utils.sql
|
||||
\o
|
||||
\set ECHO queries
|
||||
\set VERBOSITY default
|
||||
|
||||
\c :TEST_DBNAME :ROLE_SUPERUSER
|
||||
|
||||
SELECT allow_downgrade_to_apache();
|
||||
SET timescaledb.license_key='ApacheOnly';
|
||||
select * from timescaledb_information.license;
|
||||
|
@ -122,7 +122,7 @@ license_deserialize_enterprise(char *license_key, LicenseInfo *license_out)
|
||||
if (license_key_len < 1)
|
||||
return false;
|
||||
|
||||
switch (license_key[0])
|
||||
switch (TS_LICENSE_TYPE(license_key))
|
||||
{
|
||||
case LICENSE_TYPE_APACHE_ONLY:
|
||||
license_info = &no_license;
|
||||
|
@ -20,6 +20,12 @@ SELECT _timescaledb_internal.enterprise_enabled();
|
||||
t
|
||||
(1 row)
|
||||
|
||||
select * from timescaledb_information.license;
|
||||
edition | expired | expiration_time
|
||||
------------+---------+------------------------------
|
||||
enterprise | t | Sun Sep 30 17:00:00 2018 PDT
|
||||
(1 row)
|
||||
|
||||
-- changing licenses requires superuser privleges
|
||||
\set ON_ERROR_STOP 0
|
||||
SET timescaledb.license_key='CommunityLicense';
|
||||
@ -103,6 +109,12 @@ SELECT _timescaledb_internal.enterprise_enabled();
|
||||
f
|
||||
(1 row)
|
||||
|
||||
select * from timescaledb_information.license;
|
||||
edition | expired | expiration_time
|
||||
-----------+---------+-----------------
|
||||
community | f | infinity
|
||||
(1 row)
|
||||
|
||||
SET timescaledb.license_key=Default;
|
||||
SELECT _timescaledb_internal.current_license_key();
|
||||
current_license_key
|
||||
@ -122,3 +134,9 @@ SELECT _timescaledb_internal.enterprise_enabled();
|
||||
t
|
||||
(1 row)
|
||||
|
||||
select * from timescaledb_information.license;
|
||||
edition | expired | expiration_time
|
||||
------------+---------+------------------------------
|
||||
enterprise | t | Sun Sep 30 17:00:00 2018 PDT
|
||||
(1 row)
|
||||
|
||||
|
@ -6,6 +6,7 @@
|
||||
SELECT _timescaledb_internal.current_license_key();
|
||||
SELECT _timescaledb_internal.tsl_loaded();
|
||||
SELECT _timescaledb_internal.enterprise_enabled();
|
||||
select * from timescaledb_information.license;
|
||||
|
||||
-- changing licenses requires superuser privleges
|
||||
\set ON_ERROR_STOP 0
|
||||
@ -32,9 +33,10 @@ SET timescaledb.license_key='CommunityLicense';
|
||||
SELECT _timescaledb_internal.current_license_key();
|
||||
SELECT _timescaledb_internal.tsl_loaded();
|
||||
SELECT _timescaledb_internal.enterprise_enabled();
|
||||
select * from timescaledb_information.license;
|
||||
|
||||
SET timescaledb.license_key=Default;
|
||||
SELECT _timescaledb_internal.current_license_key();
|
||||
SELECT _timescaledb_internal.tsl_loaded();
|
||||
SELECT _timescaledb_internal.enterprise_enabled();
|
||||
|
||||
select * from timescaledb_information.license;
|
||||
|
Loading…
x
Reference in New Issue
Block a user