diff --git a/dgraph/cmd/zero/license.go b/dgraph/cmd/zero/license.go index a591df9e078..813fb8ac4ba 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) applyLicenseFile(path string) error { + return nil +} diff --git a/dgraph/cmd/zero/license_ee.go b/dgraph/cmd/zero/license_ee.go index 23429b1631e..f8785299015 100644 --- a/dgraph/cmd/zero/license_ee.go +++ b/dgraph/cmd/zero/license_ee.go @@ -132,3 +132,15 @@ 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) diff --git a/wiki/content/enterprise-features/index.md b/wiki/content/enterprise-features/index.md index 551b1760d37..5ac0ba2e377 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,