Skip to content

Commit

Permalink
updating pull by version to only pull versioned files
Browse files Browse the repository at this point in the history
  • Loading branch information
kendavis2 committed Oct 16, 2018
1 parent 67f5e63 commit cbe0a3d
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 18 deletions.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ When the repository has been cloned, running `$ cstore pull` in the same directo
## How to Use (3 minutes) ##

#### Install/Upgrade ####
mac: `$ curl -L -o /usr/local/bin/cstore https://github.com/turnerlabs/cstore/releases/download/v1.0.1-rc/cstore_darwin_amd64 && chmod +x /usr/local/bin/cstore`
mac: `$ curl -L -o /usr/local/bin/cstore https://github.com/turnerlabs/cstore/releases/download/v1.3.0-rc/cstore_darwin_amd64 && chmod +x /usr/local/bin/cstore`

linux: `$ curl -L -o /usr/local/bin/cstore https://github.com/turnerlabs/cstore/releases/download/v1.0.1-rc/cstore_linux_386 && chmod +x /usr/local/bin/cstore`
linux: `$ curl -L -o /usr/local/bin/cstore https://github.com/turnerlabs/cstore/releases/download/v1.3.0-rc/cstore_linux_386 && chmod +x /usr/local/bin/cstore`

The first push creates a catalog file in the same directory that can be checked into source control. Subsequent commands executed in the same directory will use the existing catalog.

Expand Down Expand Up @@ -180,9 +180,9 @@ exec ./my-application
```docker
ENTRYPOINT ["./docker-entrypoint.sh"]
```
4. Update the `Dockerfile` to install [cStore](https://github.com/turnerlabs/cstore/releases/download/v0.3.6-alpha/cstore_linux_amd64) for Linux (or the appropriate os) adding execute permissions.
4. Update the `Dockerfile` to install [cStore](https://github.com/turnerlabs/cstore/releases/download/v1.3.0-rc/cstore_linux_amd64) for Linux (or the appropriate os) adding execute permissions.
```docker
RUN curl -L -o /usr/local/bin/cstore https://github.com/turnerlabs/cstore/releases/download/v1.0.1-rc/cstore_linux_386 && chmod +x /usr/local/bin/cstore
RUN curl -L -o /usr/local/bin/cstore https://github.com/turnerlabs/cstore/releases/download/v1.3.0-rc/cstore_linux_386 && chmod +x /usr/local/bin/cstore
```
5. Update the `docker-compose.yml` file to specify which environment config should be pulled by the `docker-entrypoint.sh` script.
```docker
Expand Down
19 changes: 11 additions & 8 deletions cmd/pull.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ var secrets bool
// pullCmd represents the pull command
var pullCmd = &cobra.Command{
Use: "pull",
Short: "Restore file(s) on file system.",
Long: `Restore file(s) on file system.`,
Short: "Retrieve file(s).",
Long: `Retrieve file(s).`,
Run: func(cmd *cobra.Command, args []string) {

tags := getTags(tagList)
Expand All @@ -48,7 +48,7 @@ var pullCmd = &cobra.Command{
logger.L.Fatal(err)
}

logger.L.Printf("%d of %d file(s) restored on file system.\n", count, total)
logger.L.Printf("%d of %d file(s) retrieved.\n", count, total)
},
}

Expand All @@ -61,7 +61,7 @@ func pull(catalogPath, cVault, eVault string, args []string, tags []string) (int
return 0, 0, err
}

files := clog.FilesBy(args, tags)
files := clog.FilesBy(args, tags, version)

restoredCount := 0
totalCount := 0
Expand All @@ -74,7 +74,7 @@ func pull(catalogPath, cVault, eVault string, args []string, tags []string) (int

cv, err := vault.GetBy(credsVaultName)
if err != nil {
logger.L.Printf("\nCould not restore %s!\n", fileInfo.Path)
logger.L.Printf("\nCould not retrieve %s!\n", buildPath(root, fileInfo.Path))
logger.L.Print(err)
continue
}
Expand All @@ -86,7 +86,7 @@ func pull(catalogPath, cVault, eVault string, args []string, tags []string) (int

ev, err := vault.GetBy(encryptVaultName)
if err != nil {
logger.L.Printf("\nCould not restore %s!\n", fileInfo.Path)
logger.L.Printf("\nCould not retrieve %s!\n", buildPath(root, fileInfo.Path))
logger.L.Print(err)
continue
}
Expand Down Expand Up @@ -118,8 +118,9 @@ func pull(catalogPath, cVault, eVault string, args []string, tags []string) (int
}

b, attr, err := st.Pull(contextKey, fileInfo)

if err != nil {
logger.L.Printf("\nCould not restore %s!\n", fileInfo.Path)
logger.L.Printf("\nCould not retrieve %s!\n", buildPath(root, fileInfo.Path))
logger.L.Print(err)
continue
}
Expand All @@ -131,7 +132,7 @@ func pull(catalogPath, cVault, eVault string, args []string, tags []string) (int
tokens, err = st.GetTokens(tokens, clog.Context)

if err != nil {
logger.L.Printf("\nFailed to get tokens for %s!\n", fileInfo.Path)
logger.L.Printf("\nFailed to get tokens for %s!\n", buildPath(root, fileInfo.Path))
logger.L.Print(err)
continue
}
Expand Down Expand Up @@ -168,6 +169,8 @@ func pull(catalogPath, cVault, eVault string, args []string, tags []string) (int
}
}

logger.L.Printf(" - %s (retrieved)\n", buildPath(root, fileInfo.Path))

restoredCount++
}
}
Expand Down
2 changes: 1 addition & 1 deletion cmd/purge.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ If all files were removed successfully, the local catalog is deleted.`,

tags := getTags(tagList)

files := clog.FilesBy(args, tags)
files := clog.FilesBy(args, tags, version)

count := 0
purged := 0
Expand Down
1 change: 0 additions & 1 deletion cmd/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ var pushCmd = &cobra.Command{
if len(paths) == 0 {
if len(tags) > 0 {
paths = append(paths, clog.GetTaggedPaths(tags, true)...)
fmt.Println(paths)
} else {
paths = clog.GetFileNames()
}
Expand Down
2 changes: 1 addition & 1 deletion components/catalog/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func getContext() string {

func create() Catalog {

val := prompt.GetValFromUser("Context", getContext(), "The folder or context for the configuration files.", false)
val := prompt.GetValFromUser("Context", getContext(), "A remote parent folder for stored files. Can be a project name for easy reference.", false)

return Catalog{
Version: v1,
Expand Down
25 changes: 22 additions & 3 deletions components/catalog/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,16 +117,35 @@ func (c Catalog) GetTaggedPaths(tags []string, all bool) []string {
}

// FilesBy ...
func (c Catalog) FilesBy(args, tags []string) map[string]File {
return getFiles(c.Files, args, tags)
func (c Catalog) FilesBy(args, tags []string, version string) map[string]File {
return getFiles(c.Files, args, tags, version)
}

func getFiles(files map[string]File, paths []string, tags []string) map[string]File {
func getFiles(files map[string]File, paths []string, tags []string, version string) map[string]File {

targets := FilterByPath(files, paths)

targets = FilterByTag(targets, tags, false)

targets = FilterByVersion(targets, version)

return targets
}

//FilterByVersion ...
func FilterByVersion(files map[string]File, version string) map[string]File {
targets := map[string]File{}

if len(version) == 0 {
return files
}

for key, file := range files {
if file.VersionExists(version) {
targets[key] = file
}
}

return targets
}

Expand Down

0 comments on commit cbe0a3d

Please sign in to comment.