Exemple #1
0
// processFlags validates flags, creates and configures logger, client, etc.
func (opts *commonOptions) processFlags() (state, error) {
	// Logger.
	logLevels := map[logging.Level]gol.Level{
		logging.Debug:   gol.DEBUG,
		logging.Info:    gol.INFO,
		logging.Warning: gol.WARNING,
		logging.Error:   gol.ERROR,
	}
	logger := gologger.New(os.Stderr, logLevels[opts.localLogLevel])

	// Auth options.
	authOpts, err := opts.authFlags.Options()
	if err != nil {
		return state{}, err
	}
	authOpts.Logger = logger
	if opts.projectID == "" {
		if authOpts.ServiceAccountJSONPath != "" {
			opts.projectID = projectIDFromServiceAccountJSON(authOpts.ServiceAccountJSONPath)
		}
		if opts.projectID == "" {
			return state{}, fmt.Errorf("-project-id is required")
		}
	}

	// Client.
	httpClient, err := auth.AuthenticatedClient(auth.SilentLogin, auth.NewAuthenticator(authOpts))
	if err != nil {
		return state{}, err
	}
	client, err := cloudtail.NewClient(cloudtail.ClientOptions{
		Client:       httpClient,
		Logger:       logger,
		ProjectID:    opts.projectID,
		ResourceType: opts.resourceType,
		ResourceID:   opts.resourceID,
		LogID:        opts.logID,
	})
	if err != nil {
		return state{}, err
	}

	// Buffer.
	buffer := cloudtail.NewPushBuffer(cloudtail.PushBufferOptions{
		Client: client,
		Logger: logger,
	})

	return state{logger, client, buffer}, nil
}
Exemple #2
0
	"strings"
	"time"

	"github.com/luci/luci-go/client/authcli"
	"github.com/luci/luci-go/common/auth"
	"github.com/luci/luci-go/common/logging"
	"github.com/luci/luci-go/common/logging/gologger"
	"github.com/maruel/subcommands"
	gol "github.com/op/go-logging"

	"infra/libs/cipd"
	"infra/tools/cloudtail"
)

var authOptions = auth.Options{
	Logger:                 gologger.New(os.Stderr, gol.INFO),
	ServiceAccountJSONPath: defaultServiceAccountJSONPath(),
	Scopes: []string{
		auth.OAuthScopeEmail,
		"https://www.googleapis.com/auth/logging.write",
	},
}

// Where to look for service account JSON creds if not provided via CLI.
const (
	defaultServiceAccountPosix = "/creds/service_accounts/service-account-cloudtail.json"
	defaultServiceAccountWin   = "C:\\creds\\service_accounts\\service-account-cloudtail.json"
)

////////////////////////////////////////////////////////////////////////////////
// Common functions and structs.