-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #59 from cnabio/trishankatdatadog/cmd-to-make-keys
Improve default key management experience
- Loading branch information
Showing
18 changed files
with
417 additions
and
327 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// Most of the helper functions are adapted from github.com/theupdateframework/notary | ||
// | ||
// Figure out the proper way of making sure we are respecting the licensing from Notary | ||
// While we are also vendoring Notary directly (see LICENSE in vendor/github.com/theupdateframework/notary/LICENSE), | ||
// copying unexported functions could fall under different licensing, so we need to make sure. | ||
|
||
package tuf | ||
|
||
import ( | ||
"os" | ||
"path/filepath" | ||
"runtime" | ||
|
||
"github.com/docker/distribution/reference" | ||
"github.com/docker/docker/registry" | ||
) | ||
|
||
const ( | ||
dockerConfigDir = ".docker" | ||
) | ||
|
||
func DefaultTrustDir() string { | ||
homeEnvPath := os.Getenv("HOME") | ||
if homeEnvPath == "" && runtime.GOOS == "windows" { | ||
homeEnvPath = os.Getenv("USERPROFILE") | ||
} | ||
|
||
return filepath.Join(homeEnvPath, ".signy") | ||
} | ||
|
||
func DefaultDockerCfgDir() string { | ||
homeEnvPath := os.Getenv("HOME") | ||
if homeEnvPath == "" && runtime.GOOS == "windows" { | ||
homeEnvPath = os.Getenv("USERPROFILE") | ||
} | ||
|
||
return filepath.Join(homeEnvPath, dockerConfigDir) | ||
} | ||
|
||
// ensures the trust directory exists | ||
func EnsureTrustDir(trustDir string) error { | ||
return os.MkdirAll(trustDir, 0700) | ||
} | ||
|
||
func getRepoAndTag(name string) (*registry.RepositoryInfo, string, error) { | ||
r, err := reference.ParseNormalizedNamed(name) | ||
if err != nil { | ||
return nil, "", err | ||
} | ||
repo, err := registry.ParseRepositoryInfo(r) | ||
if err != nil { | ||
return nil, "", err | ||
} | ||
|
||
return repo, getTag(r), nil | ||
} | ||
|
||
func getTag(ref reference.Named) string { | ||
switch x := ref.(type) { | ||
case reference.Canonical, reference.Digested: | ||
return "" | ||
case reference.NamedTagged: | ||
return x.Tag() | ||
default: | ||
return "" | ||
} | ||
} |
File renamed without changes.
Oops, something went wrong.