go.fuchsia.dev/infra@v0.0.0-20240507153436-9b593402251b/cmd/gcs-util/common.go (about)

     1  // Copyright 2022 The Fuchsia Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style license that can be
     3  // found in the LICENSE file.
     4  
     5  package main
     6  
     7  import (
     8  	"time"
     9  
    10  	"github.com/maruel/subcommands"
    11  	"go.chromium.org/luci/auth"
    12  	"go.chromium.org/luci/auth/client/authcli"
    13  )
    14  
    15  const (
    16  	// The exit code emitted from an upload command when it fails due to a
    17  	// transient GCS error.
    18  	exitTransientError = 3
    19  
    20  	// The size in bytes at which files will be read and written to GCS.
    21  	chunkSize = 100 * 1024 * 1024
    22  
    23  	// A list of the objects that need their TTL refreshed.
    24  	objsToRefreshTTLTxt = "objs_to_refresh_ttl.txt"
    25  
    26  	// The number of days since the CustomTime of an object after which the
    27  	// TTL should be refreshed. This is an arbitrary value chosen to avoid
    28  	// refreshing the TTL of frequently deduplicated objects repeatedly over
    29  	// a short time period.
    30  	daysSinceCustomTime = 10
    31  
    32  	// Timeout for every file upload.
    33  	perFileUploadTimeout = 8 * time.Minute
    34  
    35  	// Metadata keys.
    36  	googleReservedFileMtime = "goog-reserved-file-mtime"
    37  )
    38  
    39  type commonFlags struct {
    40  	subcommands.CommandRunBase
    41  	authFlags authcli.Flags
    42  
    43  	parsedAuthOpts auth.Options
    44  }
    45  
    46  func (c *commonFlags) Init(authOpts auth.Options) {
    47  	c.authFlags = authcli.Flags{}
    48  	c.authFlags.Register(&c.Flags, authOpts)
    49  }
    50  
    51  func (c *commonFlags) Parse() error {
    52  	var err error
    53  	c.parsedAuthOpts, err = c.authFlags.Options()
    54  	if err != nil {
    55  		return err
    56  	}
    57  	return nil
    58  }