feat: license util config (#3248)

* feat: license util config

* address comments

* introduce census job

* add job

* fix import groups

* remove pointers
pull/3251/head
Michael Milton 3 years ago committed by GitHub
parent 7bdbe8ab8e
commit 9ae2bdfae6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,41 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package census
import (
"context"
"fmt"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/scheduler"
"github.com/hashicorp/boundary/internal/util"
)
// RegisterJob registers the census job with the provided scheduler.
func RegisterJob(ctx context.Context, s *scheduler.Scheduler, optOut bool, r db.Reader, w db.Writer) error {
const op = "census.RegisterJob"
if s == nil {
return errors.New(ctx, errors.InvalidParameter, "nil scheduler", op, errors.WithoutEvent())
}
if util.IsNil(r) {
return errors.New(ctx, errors.Internal, "nil DB reader", op, errors.WithoutEvent())
}
if util.IsNil(w) {
return errors.New(ctx, errors.Internal, "nil DB writer", op, errors.WithoutEvent())
}
if util.IsNil(optOut) {
return errors.New(ctx, errors.Internal, "nil opt out value", op, errors.WithoutEvent())
}
censusJob, err := NewCensusJobFn(ctx, optOut, r, w)
if err != nil {
return fmt.Errorf("error creating census job: %w", err)
}
if err := s.RegisterJob(ctx, censusJob); err != nil {
return errors.Wrap(ctx, err, op)
}
return nil
}

@ -0,0 +1,76 @@
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package census
import (
"context"
"time"
"github.com/hashicorp/boundary/internal/db"
"github.com/hashicorp/boundary/internal/errors"
"github.com/hashicorp/boundary/internal/scheduler"
)
var (
NewCensusJobFn = newCensusJob
RunFn = runInternal
)
type censusJob struct {
r db.Reader
w db.Writer
optOut bool
agent any
}
func newCensusJob(ctx context.Context, optOut bool, r db.Reader, w db.Writer) (*censusJob, error) {
const op = "censusJob.newCensusJob"
switch {
case r == nil:
return nil, errors.New(ctx, errors.InvalidParameter, op, "missing db.Reader")
case w == nil:
return nil, errors.New(ctx, errors.InvalidParameter, op, "missing db.Writer")
}
return &censusJob{
r: r,
w: w,
optOut: optOut,
agent: nil,
}, nil
}
// Status reports the jobs current status.
func (c *censusJob) Status() scheduler.JobStatus {
return scheduler.JobStatus{}
}
// Run performs the required work depending on the implementation.
// The context is used to notify the job that it should exit early.
func (c *censusJob) Run(ctx context.Context) error {
const op = "census.(censusJob).Run"
err := RunFn(ctx, c)
return err
}
func runInternal(ctx context.Context, c *censusJob) error {
return nil
}
// NextRunIn returns the duration until the next job run should be scheduled.
// We report as ready immediately after a successful run. This doesn't mean that
// this job will run immediately, only about as often as the configured scheduler interval.
func (c *censusJob) NextRunIn(_ context.Context) (time.Duration, error) {
return 0, nil
}
// Name is the unique name of the job.
func (c *censusJob) Name() string {
return "job_run_census"
}
// Description is the human-readable description of the job.
func (c *censusJob) Description() string {
return "Gathers and exports session usage metrics"
}

@ -148,6 +148,9 @@ type Config struct {
// sensitive. This should only be enabled for debugging purposes, and can be
// toggled with SIGHUP.
EnableWorkerAuthDebugging bool `hcl:"enable_worker_auth_debugging"`
// For opting out of license utilization reporting
Reporting Reporting `hcl:"reporting"`
}
type Controller struct {
@ -308,6 +311,14 @@ type Plugins struct {
ExecutionDir string `hcl:"execution_dir"`
}
type Reporting struct {
License License `hcl:"license"`
}
type License struct {
Enabled bool `hcl:"enabled"`
}
// DevWorker is a Config that is used for dev mode of Boundary
// workers. Supported options: WithObservationsEnabled, WithSysEventsEnabled,
// WithAuditEventsEnabled, TestWithErrorEventsEnabled

@ -451,6 +451,11 @@ func TestLoad(t *testing.T) {
ExecutionDir: "",
},
HcpbClusterId: "",
Reporting: &config.Reporting{
License: &config.License{
Enabled: false,
},
},
},
nil,
},

@ -63,3 +63,9 @@ kms "aead" {
key = "8fZBjCUfN0TzjEGLQldGY4+iE9AkOvCfjh7+p0GtRBQ="
key_id = "global_recovery"
}
reporting {
license {
enabled = false
}
}

@ -15,6 +15,7 @@ import (
"github.com/hashicorp/boundary/internal/auth/oidc"
"github.com/hashicorp/boundary/internal/auth/password"
"github.com/hashicorp/boundary/internal/authtoken"
"github.com/hashicorp/boundary/internal/census"
"github.com/hashicorp/boundary/internal/cmd/base"
"github.com/hashicorp/boundary/internal/cmd/config"
credstatic "github.com/hashicorp/boundary/internal/credential/static"
@ -536,6 +537,9 @@ func (c *Controller) registerJobs() error {
if err := cleaner.RegisterJob(c.baseContext, c.scheduler, rw); err != nil {
return err
}
if err := census.RegisterJob(c.baseContext, c.scheduler, c.conf.RawConfig.Reporting.License.Enabled, rw, rw); err != nil {
return err
}
return nil
}

Loading…
Cancel
Save