From 0af2e980831283bd8ce080475814f9272cbb076c Mon Sep 17 00:00:00 2001 From: Martin Martinez Rivera Date: Fri, 10 Apr 2020 12:34:55 -0700 Subject: [PATCH 1/5] Add option to apply enterprise license at zero's startup. --- dgraph/cmd/zero/license_ee.go | 11 +++++++++++ dgraph/cmd/zero/run.go | 8 ++++++++ 2 files changed, 19 insertions(+) diff --git a/dgraph/cmd/zero/license_ee.go b/dgraph/cmd/zero/license_ee.go index 23429b1631e..e016c3ce1e8 100644 --- a/dgraph/cmd/zero/license_ee.go +++ b/dgraph/cmd/zero/license_ee.go @@ -132,3 +132,14 @@ func (st *state) applyEnterpriseLicense(w http.ResponseWriter, r *http.Request) } x.SetStatus(w, x.Success, "Done") } + +// applyLicenseFile applies the license file stored at the given path. +func (st *state) applyLicenseFile(path string) error { + content, err := ioutil.ReadFile(path); if err != nil { + return err + } + + ctx, cancel := context.WithTimeout(context.Background(), time.Minute) + defer cancel() + return st.zero.applyLicense(ctx, bytes.NewReader(content)) +} diff --git a/dgraph/cmd/zero/run.go b/dgraph/cmd/zero/run.go index 7998d6312ba..a4e07cad6ba 100644 --- a/dgraph/cmd/zero/run.go +++ b/dgraph/cmd/zero/run.go @@ -100,6 +100,7 @@ instances to achieve high-availability. flag.String("datadog.collector", "", "Send opencensus traces to Datadog. As of now, the trace"+ " exporter does not support annotation logs and would discard them.") flag.Bool("ludicrous_mode", false, "Run zero in ludicrous mode") + flag.String("enterprise_license", "", "Path to the enterprise license file.") } func setupListener(addr string, port int, kind string) (listener net.Listener, err error) { @@ -240,6 +241,13 @@ func run() { st.serveGRPC(grpcListener, store) st.serveHTTP(httpListener) + // Apply enterprise license if one was given. + if license := Zero.Conf.GetString("enterprise_license"); len(license) > 0 { + if err := st.applyLicenseFile(license); err != nil { + glog.Warningf("Cannot apply enterprise license file %s", license) + } + } + http.HandleFunc("/health", st.pingResponse) http.HandleFunc("/state", st.getState) http.HandleFunc("/removeNode", st.removeNode) From cbdb024a9cbf2881c9cf1bbddf720337d3ba47b2 Mon Sep 17 00:00:00 2001 From: Martin Martinez Rivera Date: Fri, 10 Apr 2020 12:48:18 -0700 Subject: [PATCH 2/5] add docs. --- wiki/content/enterprise-features/index.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/wiki/content/enterprise-features/index.md b/wiki/content/enterprise-features/index.md index 8e70354cf1c..00ee89aafb4 100644 --- a/wiki/content/enterprise-features/index.md +++ b/wiki/content/enterprise-features/index.md @@ -11,10 +11,13 @@ forum](https://discuss.dgraph.io). **Dgraph enterprise features are enabled by default for 30 days in a new cluster**. After the trial period of thirty (30) days, the cluster must obtain a license from Dgraph to -continue enjoying the enterprise features released in the proprietary code. The license can -be applied to the cluster by including it as the body of a POST request and calling -`/enterpriseLicense` HTTP endpoint on any Zero server. +continue enjoying the enterprise features released in the proprietary code. +The license can be applied to the cluster by including it as the body of a POST +request and calling `/enterpriseLicense` HTTP endpoint on any Zero server. It +can also be applied by passing the path to the enterprise license file (using +the flag `--enterprise_license`) to the `dgraph zero` command used to start the +server. The second option is useful when the process needs to be automated. {{% notice "note" %}} At the conclusion of your 30-day trial period if a license has not been applied to the cluster, From 54350a4fe1f4506cab0c55adc9defbd5011ac6b0 Mon Sep 17 00:00:00 2001 From: Martin Martinez Rivera Date: Fri, 10 Apr 2020 12:49:27 -0700 Subject: [PATCH 3/5] go fmt. --- dgraph/cmd/zero/license_ee.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/dgraph/cmd/zero/license_ee.go b/dgraph/cmd/zero/license_ee.go index e016c3ce1e8..f8785299015 100644 --- a/dgraph/cmd/zero/license_ee.go +++ b/dgraph/cmd/zero/license_ee.go @@ -135,7 +135,8 @@ func (st *state) applyEnterpriseLicense(w http.ResponseWriter, r *http.Request) // applyLicenseFile applies the license file stored at the given path. func (st *state) applyLicenseFile(path string) error { - content, err := ioutil.ReadFile(path); if err != nil { + content, err := ioutil.ReadFile(path) + if err != nil { return err } From 81f18c11bdbcfc9fd4d260ed4d7d093a7bc69657 Mon Sep 17 00:00:00 2001 From: Martin Martinez Rivera Date: Fri, 10 Apr 2020 13:16:02 -0700 Subject: [PATCH 4/5] Fix oss version. --- dgraph/cmd/zero/license.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/dgraph/cmd/zero/license.go b/dgraph/cmd/zero/license.go index a591df9e078..311ee417445 100644 --- a/dgraph/cmd/zero/license.go +++ b/dgraph/cmd/zero/license.go @@ -37,3 +37,7 @@ func (n *node) updateEnterpriseState(closer *y.Closer) { func (st *state) applyEnterpriseLicense(w http.ResponseWriter, r *http.Request) { w.WriteHeader(http.StatusNotFound) } + +func (st *state) applyLicenceFile(path string) error { + return nil +} From 25b1c24ac16973abcd7d06de70bfd0a0fbaffcb4 Mon Sep 17 00:00:00 2001 From: Martin Martinez Rivera Date: Tue, 14 Apr 2020 10:42:39 -0700 Subject: [PATCH 5/5] Fix typo --- dgraph/cmd/zero/license.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dgraph/cmd/zero/license.go b/dgraph/cmd/zero/license.go index 311ee417445..813fb8ac4ba 100644 --- a/dgraph/cmd/zero/license.go +++ b/dgraph/cmd/zero/license.go @@ -38,6 +38,6 @@ func (st *state) applyEnterpriseLicense(w http.ResponseWriter, r *http.Request) w.WriteHeader(http.StatusNotFound) } -func (st *state) applyLicenceFile(path string) error { +func (st *state) applyLicenseFile(path string) error { return nil }