Showing 85 of 107 total issues

Method NonAtomicTufStore.WalkStagedTargets has a Cognitive Complexity of 27 (exceeds 20 allowed). Consider refactoring.
Open

func (store *NonAtomicTufStore) WalkStagedTargets(targetPathList []string, targetsFn tuf.TargetsWalkFunc) error {
    store.logger.Debug(fmt.Sprintf("-- NonAtomicTufStore.WalkStagedTargets %v", targetPathList))

    ctx := context.Background()

Severity: Minor
Found in server/pkg/publisher/non_atomic_tuf_store.go - About 1 hr to fix

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

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)
    }
Severity: Minor
Found in server/path_publish.go - About 1 hr to fix

    Function buildReleaseArtifacts has 58 lines of code (exceeds 50 allowed). Consider refactoring.
    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
        }
    Severity: Minor
    Found in server/path_release.go - About 1 hr to fix

      Function useCmd has 58 lines of code (exceeds 50 allowed). Consider refactoring.
      Open

      func useCmd() *cobra.Command {
          var noSelfUpdate bool
          var shell string
      
          cmd := &cobra.Command{
      Severity: Minor
      Found in client/cmd/trdl/use.go - About 1 hr to fix

        Method Backend.Periodic has 56 lines of code (exceeds 50 allowed). Consider refactoring.
        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)
            }
        Severity: Minor
        Found in server/periodic.go - About 1 hr to fix

          Method Client.doSelfUpdate has 12 return statements (exceeds 4 allowed).
          Open

          func (c Client) doSelfUpdate(autocleanReleases bool) error {
              channel, err := c.processRepoOptionalChannel(trdl.SelfUpdateDefaultRepo, "")
              if err != nil {
                  if _, ok := err.(*RepositoryNotInitializedError); !ok {
                      return err
          Severity: Major
          Found in client/pkg/client/client.go - About 1 hr to fix

            Method Manager.pathTaskLogRead has 12 return statements (exceeds 4 allowed).
            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)
            
            
            Severity: Major
            Found in server/pkg/tasks_manager/backend.go - About 1 hr to fix

              Method Backend.Periodic has 11 return statements (exceeds 4 allowed).
              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)
                  }
              Severity: Major
              Found in server/periodic.go - About 1 hr to fix

                Function ForEachWorktreeFile has 11 return statements (exceeds 4 allowed).
                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)
                    }
                Severity: Major
                Found in server/pkg/git/repository.go - About 1 hr to fix

                  Method TufRepoRotator.Rotate has 10 return statements (exceeds 4 allowed).
                  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")
                  
                  
                  Severity: Major
                  Found in server/pkg/publisher/tuf_repo_rotator.go - About 1 hr to fix

                    Function updateCmd has 9 return statements (exceeds 4 allowed).
                    Open

                    func updateCmd() *cobra.Command {
                        var noSelfUpdate bool
                        var autoclean bool
                        var inBackground bool
                        var backgroundStdoutFile string
                    Severity: Major
                    Found in client/cmd/trdl/update.go - About 55 mins to fix

                      Function buildReleaseArtifacts has 9 return statements (exceeds 4 allowed).
                      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
                          }
                      Severity: Major
                      Found in server/path_release.go - About 55 mins to fix

                        Function VerifyTagSignatures has 9 return statements (exceeds 4 allowed).
                        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)
                            }
                        Severity: Major
                        Found in server/pkg/git/signatures.go - About 55 mins to fix

                          Method Publisher.setRepositoryKeys has 9 return statements (exceeds 4 allowed).
                          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)
                              }
                          Severity: Major
                          Found in server/pkg/publisher/publisher.go - About 55 mins to fix

                            Method Publisher.fetchPGPSigningKey has 8 return statements (exceeds 4 allowed).
                            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)
                                }
                            Severity: Major
                            Found in server/pkg/publisher/publisher.go - About 50 mins to fix

                              Function switchTaskToCompletedInStorage has 8 return statements (exceeds 4 allowed).
                              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)
                                  }
                              Severity: Major
                              Found in server/pkg/tasks_manager/task.go - About 50 mins to fix

                                Method Client.DoSelfUpdate has 8 return statements (exceeds 4 allowed).
                                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)
                                    }
                                Severity: Major
                                Found in client/pkg/client/client.go - About 50 mins to fix

                                  Function ValidatePublishConfig has 8 return statements (exceeds 4 allowed).
                                  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)
                                      }
                                  Severity: Major
                                  Found in server/path_publish.go - About 50 mins to fix

                                    Function useCmd has 8 return statements (exceeds 4 allowed).
                                    Open

                                    func useCmd() *cobra.Command {
                                        var noSelfUpdate bool
                                        var shell string
                                    
                                        cmd := &cobra.Command{
                                    Severity: Major
                                    Found in client/cmd/trdl/use.go - About 50 mins to fix

                                      Function binPathCmd has 7 return statements (exceeds 4 allowed).
                                      Open

                                      func binPathCmd() *cobra.Command {
                                          cmd := &cobra.Command{
                                              Use:                   "bin-path REPO GROUP [CHANNEL]",
                                              Short:                 "Get the directory with software binaries",
                                              DisableFlagsInUseLine: true,
                                      Severity: Major
                                      Found in client/cmd/trdl/bin_path.go - About 45 mins to fix
                                        Severity
                                        Category
                                        Status
                                        Source
                                        Language