forked from cockroachdb/cockroach
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
demo: Get a temporary license upon demo startup
There is a wider discussion/design going on to serve licenses in a more general way in the future, so this commit is not aiming for a future-proof design, but instead an MVP to allow users to demo enterprise features within `cockroach demo`. We are not concerned about offline usage of enterprise features as users can obtain a license and enable features manually using SET. Fixes cockroachdb#40222. Release note (cli change): cockroach demo attempts to contact a license server to obtain a temporary license. cockroach demo now enables telemetry for the demo cluster. This feature can be opted out of by setting the `COCKROACH_SKIP_ENABLING_DIAGNOSTIC_REPORTING` environment variable (https://www.cockroachlabs.com/docs/stable/diagnostics-reporting.html).
- Loading branch information
Showing
6 changed files
with
134 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Copyright 2019 The Cockroach Authors. | ||
// | ||
// Licensed as a CockroachDB Enterprise file under the Cockroach Community | ||
// License (the "License"); you may not use this file except in compliance with | ||
// the License. You may obtain a copy of the License at | ||
// | ||
// https://github.com/cockroachdb/cockroach/blob/master/licenses/CCL.txt | ||
|
||
package cliccl | ||
|
||
import ( | ||
gosql "database/sql" | ||
"fmt" | ||
"io/ioutil" | ||
"net/http" | ||
"time" | ||
|
||
"github.com/cockroachdb/cockroach/pkg/build" | ||
"github.com/cockroachdb/cockroach/pkg/cli" | ||
"github.com/cockroachdb/cockroach/pkg/util/uuid" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// TODO (rohany): change this once another endpoint is setup for getting licenses. | ||
// This URL grants a license that is valid for 1 hour. | ||
const licenseURL = "https://register.cockroachdb.com/api/prodtest" | ||
|
||
func getLicense(clusterID uuid.UUID) (string, error) { | ||
client := &http.Client{ | ||
Timeout: 5 * time.Second, | ||
} | ||
// Send some extra information to the endpoint. | ||
params := fmt.Sprintf("?type=demo&version=%s&clusterid=%s", build.VersionPrefix(), clusterID.String()) | ||
resp, err := client.Get(licenseURL + params) | ||
if err != nil { | ||
return "", err | ||
} | ||
defer resp.Body.Close() | ||
if resp.StatusCode != http.StatusOK { | ||
return "", errors.New("unable to connect to licensing endpoint") | ||
} | ||
bodyBytes, err := ioutil.ReadAll(resp.Body) | ||
if err != nil { | ||
return "", err | ||
} | ||
return string(bodyBytes), nil | ||
} | ||
|
||
func getAndApplyLicense(db *gosql.DB, clusterID uuid.UUID, org string) (bool, error) { | ||
license, err := getLicense(clusterID) | ||
if err != nil { | ||
return false, nil | ||
} | ||
if _, err := db.Exec(`SET CLUSTER SETTING cluster.organization = $1`, org); err != nil { | ||
return false, err | ||
} | ||
if _, err := db.Exec(`SET CLUSTER SETTING enterprise.license = $1`, license); err != nil { | ||
return false, err | ||
} | ||
return true, nil | ||
} | ||
|
||
func init() { | ||
// Set the GetAndApplyLicense function within cockroach demo. | ||
// This separation is done to avoid using enterprise features in an OSS/BSL build. | ||
cli.GetAndApplyLicense = getAndApplyLicense | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#! /usr/bin/env expect -f | ||
|
||
source [file join [file dirname $argv0] common.tcl] | ||
|
||
start_test "Check cockroach demo telemetry and license check can be disabled" | ||
|
||
# set the proper environment variable | ||
set env(COCKROACH_SKIP_ENABLING_DIAGNOSTIC_REPORTING) "true" | ||
spawn $argv demo | ||
# wait for the CLI to start up | ||
eexpect "movr>" | ||
# send a request for an enterprise feature | ||
send "alter table vehicles partition by list (city) (partition p1 values in ('nyc'));\n" | ||
# expect that it failed, as no license was requested. | ||
eexpect "use of partitions requires an enterprise license" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters