Skip to content

Commit

Permalink
move FileExists to internal package
Browse files Browse the repository at this point in the history
  • Loading branch information
dsa0x committed Aug 17, 2022
1 parent 5d2b5d3 commit 4e3efd0
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 17 deletions.
7 changes: 4 additions & 3 deletions cmd/cosign/cli/generate/generate_key_pair.go
Expand Up @@ -18,12 +18,12 @@ package generate
import (
"context"
"crypto"
"errors"
"fmt"
"io"
"os"
"strings"

"github.com/pkg/errors"
"github.com/sigstore/cosign/pkg/cosign/git"
"github.com/sigstore/cosign/pkg/cosign/git/github"
"github.com/sigstore/cosign/pkg/cosign/git/gitlab"
Expand All @@ -32,6 +32,7 @@ import (
"github.com/sigstore/cosign/pkg/cosign/kubernetes"
"github.com/sigstore/sigstore/pkg/cryptoutils"
"github.com/sigstore/sigstore/pkg/signature/kms"
icos "github.com/sigstore/cosign/internal/pkg/cosign"
)

var (
Expand Down Expand Up @@ -85,9 +86,9 @@ func GenerateKeyPairCmd(ctx context.Context, kmsVal string, args []string) error
return err
}

fileExists, err := cosign.FileExists("cosign.key")
fileExists, err := icos.FileExists("cosign.key")
if err != nil {
return err
return errors.Wrap(err, "error checking if cosign.key exists")
}

if fileExists {
Expand Down
6 changes: 4 additions & 2 deletions cmd/cosign/cli/importkeypair/import_key_pair.go
Expand Up @@ -21,6 +21,8 @@ import (
"io"
"os"

"github.com/pkg/errors"
icos "github.com/sigstore/cosign/internal/pkg/cosign"
"github.com/sigstore/cosign/pkg/cosign"
)

Expand All @@ -36,9 +38,9 @@ func ImportKeyPairCmd(ctx context.Context, keyVal string, args []string) error {
return err
}

fileExists, err := cosign.FileExists("import-cosign.key\000x")
fileExists, err := icos.FileExists("import-cosign.key")
if err != nil {
return err
return errors.Wrap(err, "error checking if import-cosign.key exists")
}

if fileExists {
Expand Down
28 changes: 28 additions & 0 deletions internal/pkg/cosign/common.go
@@ -0,0 +1,28 @@
// Copyright 2021 The Sigstore Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package cosign

import "os"

func FileExists(filename string) (bool, error) {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
return false, nil
}
if err != nil {
return false, err
}
return !info.IsDir(), nil
}
File renamed without changes.
12 changes: 0 additions & 12 deletions pkg/cosign/common.go
Expand Up @@ -26,18 +26,6 @@ import (
"golang.org/x/term"
)

// TODO(jason): Move this to an internal package.
func FileExists(filename string) (bool, error) {
info, err := os.Stat(filename)
if os.IsNotExist(err) {
return false, nil
}
if err != nil {
return false, err
}
return !info.IsDir(), nil
}

// ConfirmPrompt prompts the user for confirmation for an action. Supports skipping
// the confirmation prompt when skipConfirmation is set.
// TODO(jason): Move this to an internal package.
Expand Down

0 comments on commit 4e3efd0

Please sign in to comment.