Merge pull request #535 from aluzzardi/dagger-homedir

use ~/.config/dagger rather than ~/.dagger
This commit is contained in:
Andrea Luzzardi 2021-06-01 13:23:43 -07:00 committed by GitHub
commit e86cb7be6d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 31 additions and 9 deletions

View File

@ -86,8 +86,8 @@ jobs:
env: env:
DAGGER_AGE_KEY: ${{ secrets.DAGGER_AGE_KEY }} DAGGER_AGE_KEY: ${{ secrets.DAGGER_AGE_KEY }}
run: | run: |
mkdir ~/.dagger mkdir -p ~/.config/dagger
echo "$DAGGER_AGE_KEY" > ~/.dagger/keys.txt echo "$DAGGER_AGE_KEY" > ~/.config/dagger/keys.txt
- name: Login to Docker Hub - name: Login to Docker Hub
uses: docker/login-action@v1 uses: docker/login-action@v1

View File

@ -21,7 +21,7 @@ import (
const ( const (
defaultVersion = "devel" defaultVersion = "devel"
versionFile = "~/.dagger/version-check" versionFile = "~/.config/dagger/version-check"
versionURL = "https://releases.dagger.io/dagger/latest_version" versionURL = "https://releases.dagger.io/dagger/latest_version"
) )
@ -168,7 +168,7 @@ func checkVersion() {
baseDir := path.Dir(versionFilePath) baseDir := path.Dir(versionFilePath)
if _, err := os.Stat(baseDir); os.IsNotExist(err) { if _, err := os.Stat(baseDir); os.IsNotExist(err) {
if err := os.MkdirAll(baseDir, 0755); err != nil { if err := os.MkdirAll(baseDir, 0700); err != nil {
// mkdir fails, ignore silently // mkdir fails, ignore silently
return return
} }

View File

@ -5,7 +5,6 @@ import (
"errors" "errors"
"fmt" "fmt"
"os" "os"
"path"
"path/filepath" "path/filepath"
"time" "time"
@ -15,12 +14,35 @@ import (
) )
func Path() (string, error) { func Path() (string, error) {
h, err := homedir.Dir() keysFile, err := homedir.Expand("~/.config/dagger/keys.txt")
if err != nil { if err != nil {
return "", err return "", err
} }
return path.Join(h, ".dagger", "keys.txt"), nil // if the keys file doesn't exist, attempt a migration
if _, err := os.Stat(keysFile); errors.Is(err, os.ErrNotExist) {
migrateKeys(keysFile)
}
return keysFile, nil
}
// migrateKeys attempts a migration from `~/.dagger/keys.txt` to `~/.config/dagger/keys.txt`
func migrateKeys(keysFile string) error {
oldKeysFile, err := homedir.Expand("~/.dagger/keys.txt")
if err != nil {
return err
}
if _, err := os.Stat(oldKeysFile); err != nil {
return err
}
if err := os.MkdirAll(filepath.Dir(keysFile), 0700); err != nil {
return err
}
return os.Rename(oldKeysFile, keysFile)
} }
func Default(ctx context.Context) (string, error) { func Default(ctx context.Context) (string, error) {
@ -49,7 +71,7 @@ func Generate(ctx context.Context) (string, error) {
return "", fmt.Errorf("internal error: %v", err) return "", fmt.Errorf("internal error: %v", err)
} }
if err := os.MkdirAll(filepath.Dir(keysFile), 0755); err != nil { if err := os.MkdirAll(filepath.Dir(keysFile), 0700); err != nil {
return "", err return "", err
} }
f, err := os.OpenFile(keysFile, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0600) f, err := os.OpenFile(keysFile, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0600)

View File

@ -13,7 +13,7 @@ common_setup() {
DAGGER_WORKSPACE="$(mktemp -d -t dagger-workspace-XXXXXX)" DAGGER_WORKSPACE="$(mktemp -d -t dagger-workspace-XXXXXX)"
export DAGGER_WORKSPACE export DAGGER_WORKSPACE
SOPS_AGE_KEY_FILE=~/.dagger/keys.txt SOPS_AGE_KEY_FILE=~/.config/dagger/keys.txt
export SOPS_AGE_KEY_FILE export SOPS_AGE_KEY_FILE
} }