Showing 85 of 107 total issues
Method NonAtomicTufStore.WalkStagedTargets
has a Cognitive Complexity of 27 (exceeds 20 allowed). Consider refactoring. Open
Open
func (store *NonAtomicTufStore) WalkStagedTargets(targetPathList []string, targetsFn tuf.TargetsWalkFunc) error {
store.logger.Debug(fmt.Sprintf("-- NonAtomicTufStore.WalkStagedTargets %v", targetPathList))
ctx := context.Background()
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Function ValidatePublishConfig
has 59 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func ValidatePublishConfig(ctx context.Context, publisher publisher.Interface, publisherRepository publisher.RepositoryInterface, config *config.TrdlChannels, logger hclog.Logger) error {
existingReleases, err := publisher.GetExistingReleases(ctx, publisherRepository)
if err != nil {
return fmt.Errorf("error getting existing targets: %w", err)
}
Function buildReleaseArtifacts
has 58 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func buildReleaseArtifacts(ctx context.Context, tarWriter *nio.PipeWriter, gitRepo *git.Repository, fromImage string, runCommands []string, logger hclog.Logger) (error, func() error) {
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
return fmt.Errorf("unable to create docker client: %w", err), nil
}
Function useCmd
has 58 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func useCmd() *cobra.Command {
var noSelfUpdate bool
var shell string
cmd := &cobra.Command{
Method Backend.Periodic
has 56 lines of code (exceeds 50 allowed). Consider refactoring. Open
Open
func (b *Backend) Periodic(ctx context.Context, req *logical.Request) error {
entry, err := req.Storage.Get(ctx, lastPeriodicRunTimestampKey)
if err != nil {
return fmt.Errorf("unable to get key %q from storage: %w", lastPeriodicRunTimestampKey, err)
}
Method Client.doSelfUpdate
has 12 return statements (exceeds 4 allowed). Open
Open
func (c Client) doSelfUpdate(autocleanReleases bool) error {
channel, err := c.processRepoOptionalChannel(trdl.SelfUpdateDefaultRepo, "")
if err != nil {
if _, ok := err.(*RepositoryNotInitializedError); !ok {
return err
Method Manager.pathTaskLogRead
has 12 return statements (exceeds 4 allowed). Open
Open
func (m *Manager) pathTaskLogRead(ctx context.Context, req *logical.Request, fields *framework.FieldData) (*logical.Response, error) {
offset := fields.Get(fieldNameOffset).(int)
limit := fields.Get(fieldNameLimit).(int)
uuid := fields.Get(fieldNameUUID).(string)
Method Backend.Periodic
has 11 return statements (exceeds 4 allowed). Open
Open
func (b *Backend) Periodic(ctx context.Context, req *logical.Request) error {
entry, err := req.Storage.Get(ctx, lastPeriodicRunTimestampKey)
if err != nil {
return fmt.Errorf("unable to get key %q from storage: %w", lastPeriodicRunTimestampKey, err)
}
Function ForEachWorktreeFile
has 11 return statements (exceeds 4 allowed). Open
Open
func ForEachWorktreeFile(gitRepo *git.Repository, fileFunc func(path, link string, fileReader io.Reader, info os.FileInfo) error) error {
w, err := gitRepo.Worktree()
if err != nil {
return fmt.Errorf("unable to get git repository worktree: %w", err)
}
Method TufRepoRotator.Rotate
has 10 return statements (exceeds 4 allowed). Open
Open
func (rotator *TufRepoRotator) Rotate(logger hclog.Logger, now time.Time) error {
var changedRoot, changedTargets, changedSnapshot, changedTimestamp bool
logger.Debug("start rotating expiration timestamps and versions of TUF repository roles")
Function updateCmd
has 9 return statements (exceeds 4 allowed). Open
Open
func updateCmd() *cobra.Command {
var noSelfUpdate bool
var autoclean bool
var inBackground bool
var backgroundStdoutFile string
Function buildReleaseArtifacts
has 9 return statements (exceeds 4 allowed). Open
Open
func buildReleaseArtifacts(ctx context.Context, tarWriter *nio.PipeWriter, gitRepo *git.Repository, fromImage string, runCommands []string, logger hclog.Logger) (error, func() error) {
cli, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation())
if err != nil {
return fmt.Errorf("unable to create docker client: %w", err), nil
}
Function VerifyTagSignatures
has 9 return statements (exceeds 4 allowed). Open
Open
func VerifyTagSignatures(repo *git.Repository, tagName string, trustedPGPPublicKeys []string, requiredNumberOfVerifiedSignatures int, logger hclog.Logger) error {
tr, err := repo.Tag(tagName)
if err != nil {
return fmt.Errorf("unable to get tag: %w", err)
}
Method Publisher.setRepositoryKeys
has 9 return statements (exceeds 4 allowed). Open
Open
func (publisher *Publisher) setRepositoryKeys(ctx context.Context, storage logical.Storage, repository RepositoryInterface, opts setRepositoryKeysOptions) error {
entry, err := storage.Get(ctx, storageKeyTufRepositoryKeys)
if err != nil {
return fmt.Errorf("error getting storage private keys json entry by the key %q: %w", storageKeyTufRepositoryKeys, err)
}
Method Publisher.fetchPGPSigningKey
has 8 return statements (exceeds 4 allowed). Open
Open
func (publisher *Publisher) fetchPGPSigningKey(ctx context.Context, storage logical.Storage, initializeKey bool) (*pgp.RSASigningKey, error) {
entry, err := storage.Get(ctx, storageKeyPGPSigningKey)
if err != nil {
return nil, fmt.Errorf("error getting storage pgp signing key json entry by storage key %q: %w", storageKeyPGPSigningKey, err)
}
Function switchTaskToCompletedInStorage
has 8 return statements (exceeds 4 allowed). Open
Open
func switchTaskToCompletedInStorage(ctx context.Context, storage logical.Storage, status taskStatus, uuid string, opts switchTaskToCompletedInStorageOptions) error {
// validate new status
if !isCompletedTaskStatus(status) {
return fmt.Errorf("runtime error: task in completed state cannot be with status %q", status)
}
Method Client.DoSelfUpdate
has 8 return statements (exceeds 4 allowed). Open
Open
func (c Client) DoSelfUpdate(autocleanReleases bool) error {
acquired, lock, err := c.locker.Acquire(selfUpdateLockFilename, lockgate.AcquireOptions{Shared: false, NonBlocking: true})
if err != nil {
return fmt.Errorf("unable to acquire lock: %w", err)
}
Function ValidatePublishConfig
has 8 return statements (exceeds 4 allowed). Open
Open
func ValidatePublishConfig(ctx context.Context, publisher publisher.Interface, publisherRepository publisher.RepositoryInterface, config *config.TrdlChannels, logger hclog.Logger) error {
existingReleases, err := publisher.GetExistingReleases(ctx, publisherRepository)
if err != nil {
return fmt.Errorf("error getting existing targets: %w", err)
}
Function useCmd
has 8 return statements (exceeds 4 allowed). Open
Open
func useCmd() *cobra.Command {
var noSelfUpdate bool
var shell string
cmd := &cobra.Command{
Function binPathCmd
has 7 return statements (exceeds 4 allowed). Open
Open
func binPathCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "bin-path REPO GROUP [CHANNEL]",
Short: "Get the directory with software binaries",
DisableFlagsInUseLine: true,