Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Push command #256

Closed
wants to merge 58 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
e7e6d49
Revert "revert push command"
dominik-przybyl-wttech Apr 9, 2024
f9e017d
optimize regex
dominik-przybyl-wttech Apr 9, 2024
bc0d52f
refactor
dominik-przybyl-wttech May 6, 2024
99124e4
Merge branch 'main' into push-command
dominik-przybyl-wttech May 7, 2024
cc821ff
refactor
dominik-przybyl-wttech May 8, 2024
2dfe735
refactor
dominik-przybyl-wttech May 8, 2024
521caac
refactor
dominik-przybyl-wttech May 9, 2024
4adbc46
refactor
dominik-przybyl-wttech May 14, 2024
b38c131
refactor
dominik-przybyl-wttech May 14, 2024
424bcd2
minor
dominik-przybyl-wttech May 14, 2024
1637553
refactor
dominik-przybyl-wttech May 14, 2024
e2588b1
refactor
dominik-przybyl-wttech May 15, 2024
43b5612
refactor
dominik-przybyl-wttech May 17, 2024
7125182
minor
dominik-przybyl-wttech May 17, 2024
222a19e
added tests
dominik-przybyl-wttech May 18, 2024
c9d72a2
minor
dominik-przybyl-wttech May 19, 2024
c09427c
minor
dominik-przybyl-wttech May 19, 2024
1fc058f
refactor
dominik-przybyl-wttech May 19, 2024
605fbaf
refactor after CR
dominik-przybyl-wttech May 21, 2024
c7765d7
typo
dominik-przybyl-wttech May 21, 2024
99d89c1
fixed the large file issue (greater than 64KB)
dominik-przybyl-wttech May 22, 2024
6fbcf2f
Merge branch 'main' into push-command
dominik-przybyl-wttech Jun 9, 2024
03cc839
minor
dominik-przybyl-wttech Jun 10, 2024
eff71ee
Merge branch 'main' into push-command
dominik-przybyl-wttech Aug 5, 2024
8a2ca96
updated go dependencies
dominik-przybyl-wttech Aug 5, 2024
087e4ce
Merge branch 'small_fixes' into push-command
dominik-przybyl-wttech Aug 5, 2024
b94d5c8
Merge branch 'main' into push-command
dominik-przybyl-wttech Aug 6, 2024
589f19b
added test
dominik-przybyl-wttech Aug 20, 2024
63d8f57
minor
dominik-przybyl-wttech Aug 21, 2024
5fddff0
fix .content.xml file push
dominik-przybyl-wttech Aug 21, 2024
b67d822
fix .content.xml file push
dominik-przybyl-wttech Aug 22, 2024
5cfb16f
minor
dominik-przybyl-wttech Aug 22, 2024
c1c0406
refactor
dominik-przybyl-wttech Aug 22, 2024
5cbc41f
refactor
dominik-przybyl-wttech Aug 22, 2024
a8f78f8
refactor
dominik-przybyl-wttech Aug 22, 2024
9b85802
remove JCRContentFile const
dominik-przybyl-wttech Aug 22, 2024
e4707f0
simplify pull file
dominik-przybyl-wttech Aug 22, 2024
e1399aa
simplify pull file
dominik-przybyl-wttech Aug 22, 2024
88a3fa4
Merge branch 'main' into push-command
dominik-przybyl-wttech Aug 23, 2024
6a62db3
simplify pull file
dominik-przybyl-wttech Aug 23, 2024
055ae03
simplify pull file
dominik-przybyl-wttech Aug 23, 2024
90cf57d
Merge branch 'simplify-pull-file' into push-command
dominik-przybyl-wttech Aug 24, 2024
23879c1
minor
dominik-przybyl-wttech Aug 24, 2024
f5a3ee7
minor
dominik-przybyl-wttech Aug 24, 2024
53197ac
minor
dominik-przybyl-wttech Aug 24, 2024
0633cb8
minor
dominik-przybyl-wttech Aug 24, 2024
0e4accf
refactor
dominik-przybyl-wttech Aug 24, 2024
845f881
refactor
dominik-przybyl-wttech Aug 24, 2024
6fbf1c9
fixed .content.xml issue
dominik-przybyl-wttech Aug 28, 2024
5abac45
minor
Aug 28, 2024
a543970
minor
Aug 28, 2024
418f4de
refactor
Aug 29, 2024
15f0597
minor
Sep 18, 2024
1ff7fd5
fixed namespace cleanup when filename contains namespace (e.g. _cq_, …
Sep 19, 2024
931acf8
Merge branch 'fix-namespace-clean' into push-command
Sep 20, 2024
800a15e
minor
Sep 20, 2024
f922f78
minor
Sep 20, 2024
f648f41
Merge branch 'push-command' of github.com:wttech/aemc into push-command
Sep 20, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
118 changes: 108 additions & 10 deletions cmd/aem/content.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import (
"github.com/wttech/aemc/pkg"
"github.com/wttech/aemc/pkg/common/pathx"
"github.com/wttech/aemc/pkg/content"
"os"
"path/filepath"
"strings"
)

Expand All @@ -17,6 +19,7 @@ func (c *CLI) contentCmd() *cobra.Command {
}
cmd.AddCommand(c.contentCleanCmd())
cmd.AddCommand(c.contentPullCmd())
cmd.AddCommand(c.contentPushCmd())
cmd.AddCommand(c.contentDownloadCmd())
cmd.AddCommand(c.contentCopyCmd())
return cmd
Expand Down Expand Up @@ -74,7 +77,7 @@ func (c *CLI) contentDownloadCmd() *cobra.Command {
}
pid, _ := cmd.Flags().GetString("pid")
targetFile, _ := cmd.Flags().GetString("target-file")
filterRoots, _ := cmd.Flags().GetStringSlice("filter-roots")
filterRoots := determineFilterRoots(cmd)
filterFile, _ := cmd.Flags().GetString("filter-file")
if err = instance.ContentManager().Download(targetFile, pkg.PackageCreateOpts{
PID: pid,
Expand Down Expand Up @@ -108,8 +111,6 @@ func (c *CLI) contentPullCmd() *cobra.Command {
c.Error(err)
return
}
clean, _ := cmd.Flags().GetBool("clean")
replace, _ := cmd.Flags().GetBool("replace")
dir, err := determineContentDir(cmd)
if err != nil {
c.Error(err)
Expand All @@ -120,21 +121,24 @@ func (c *CLI) contentPullCmd() *cobra.Command {
c.Error(err)
return
}
filterRoots := determineFilterRoots(cmd)
filterFile, _ := cmd.Flags().GetString("filter-file")
excludePatterns := determineExcludePatterns(cmd)
clean, _ := cmd.Flags().GetBool("clean")
replace, _ := cmd.Flags().GetBool("replace")
if dir != "" {
filterRoots, _ := cmd.Flags().GetStringSlice("filter-roots")
filterFile, _ := cmd.Flags().GetString("filter-file")
if err = instance.ContentManager().PullDir(dir, clean, replace, pkg.PackageCreateOpts{
FilterRoots: filterRoots,
FilterFile: filterFile,
ContentDir: dir,
}); err != nil {
c.Error(err)
return
}
c.SetOutput("dir", dir)
} else if file != "" {
if err = instance.ContentManager().PullFile(file, clean, pkg.PackageCreateOpts{
ContentFile: file,
FilterRoots: filterRoots,
ExcludePatterns: excludePatterns,
}); err != nil {
c.Error(err)
return
Expand All @@ -156,6 +160,57 @@ func (c *CLI) contentPullCmd() *cobra.Command {
return cmd
}

func (c *CLI) contentPushCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "push",
Aliases: []string{"ps"},
Short: "Push content from JCR root directory or local file to running instance",
Run: func(cmd *cobra.Command, args []string) {
instance, err := c.aem.InstanceManager().One()
if err != nil {
c.Error(err)
return
}
dir, err := determineContentDir(cmd)
if err != nil {
c.Error(err)
return
}
file, err := determineContentFile(cmd)
if err != nil {
c.Error(err)
return
}
path := dir
if path == "" {
path = file
}
filterRoots := determineFilterRoots(cmd)
excludePatterns := determineExcludePatterns(cmd)
clean, _ := cmd.Flags().GetBool("clean")
if err = instance.ContentManager().Push(path, clean, pkg.PackageCreateOpts{
FilterRoots: filterRoots,
ExcludePatterns: excludePatterns,
}); err != nil {
c.Error(err)
return
}
if dir != "" {
c.SetOutput("dir", dir)
} else if file != "" {
c.SetOutput("file", file)
}
c.Changed("content pushed")
},
}
cmd.Flags().StringP("dir", "d", "", "JCR root path")
cmd.Flags().StringP("file", "f", "", "Local file path")
cmd.Flags().StringP("path", "p", "", "JCR root path or local file path")
cmd.MarkFlagsOneRequired("dir", "file", "path")
cmd.Flags().Bool("clean", false, "Normalize content while uploading")
return cmd
}

func (c *CLI) contentCopyCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "copy",
Expand All @@ -172,7 +227,7 @@ func (c *CLI) contentCopyCmd() *cobra.Command {
c.Error(err)
return
}
filterRoots, _ := cmd.Flags().GetStringSlice("filter-roots")
filterRoots := determineFilterRoots(cmd)
filterFile, _ := cmd.Flags().GetString("filter-file")
clean, _ := cmd.Flags().GetBool("clean")
if err = instance.ContentManager().Copy(targetInstance, clean, pkg.PackageCreateOpts{
Expand Down Expand Up @@ -221,7 +276,7 @@ func determineContentDir(cmd *cobra.Command) (string, error) {
return "", fmt.Errorf("content path '%s' does not contain '%s'", path, content.JCRRoot)
}
if path != "" && !pathx.Exists(path) {
return "", fmt.Errorf("content path does not exist: %s", path)
return "", fmt.Errorf("content path '%s' need to exist on file system; consider using 'dir' or 'file' parameter otherwise", path)
}
if path != "" && pathx.IsDir(path) {
return path, nil
Expand All @@ -239,10 +294,53 @@ func determineContentFile(cmd *cobra.Command) (string, error) {
return "", fmt.Errorf("content path '%s' does not contain '%s'", path, content.JCRRoot)
}
if path != "" && !pathx.Exists(path) {
return "", fmt.Errorf("content path does not exist: %s", path)
return "", fmt.Errorf("content path '%s' need to exist on file system; consider using 'dir' or 'file' parameter otherwise", path)
}
if path != "" && pathx.IsFile(path) {
return path, nil
}
return file, nil
}

func determineFilterRoots(cmd *cobra.Command) []string {
filterRoots, _ := cmd.Flags().GetStringSlice("filter-roots")
if len(filterRoots) > 0 {
return filterRoots
}
filterFile, _ := cmd.Flags().GetString("filter-file")
if filterFile != "" {
return nil
}
dir, _ := determineContentDir(cmd)
if dir != "" {
return []string{pkg.DetermineFilterRoot(dir)}
}
file, _ := determineContentFile(cmd)
if file != "" {
return []string{pkg.DetermineFilterRoot(file)}
}
return nil
}

func determineExcludePatterns(cmd *cobra.Command) []string {
file, _ := determineContentFile(cmd)
if file == "" || !strings.HasSuffix(file, content.JCRContentFile) {
return nil
}

dir := filepath.Dir(file)
entries, err := os.ReadDir(dir)
if err != nil {
return nil
}

var excludePatterns []string
for _, entry := range entries {
if entry.Name() != content.JCRContentFile {
jcrPath := pkg.DetermineFilterRoot(filepath.Join(dir, entry.Name()))
excludePattern := fmt.Sprintf("%s(/.*)?", jcrPath)
excludePatterns = append(excludePatterns, excludePattern)
}
}
return excludePatterns
}
6 changes: 2 additions & 4 deletions cmd/aem/package.go
Original file line number Diff line number Diff line change
Expand Up @@ -506,8 +506,7 @@ func (c *CLI) pkgPathByFlags(cmd *cobra.Command) (string, error) {
path := c.aem.BaseOpts().TmpDir + "/package/" + fileName
if !pathx.Exists(path) {
log.Infof("downloading package from URL '%s' to file '%s'", url, path)
err := httpx.DownloadOnce(url, path)
if err != nil {
if err := httpx.DownloadOnce(url, path); err != nil {
return "", err
}
log.Infof("downloaded package from URL '%s' to file '%s'", url, path)
Expand Down Expand Up @@ -598,8 +597,7 @@ func (c *CLI) pkgUpdateCmd() *cobra.Command {
return
}
filterRoots, _ := cmd.Flags().GetStringSlice("filter-roots")
err = p.UpdateFilters(pkg.NewPackageFilters(filterRoots))
if err != nil {
if err = p.UpdateFilters(pkg.NewPackageFilters(filterRoots)); err != nil {
c.Error(err)
return
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/common/pathx/pathx.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,10 @@ func DirAndFileName(path string) (string, string) {

func RandomDir(tmpDir string, prefix string) string {
suffix, _ := goutils.RandomNumeric(8)
return filepath.Join(tmpDir, prefix+"_"+suffix)
return Abs(filepath.Join(tmpDir, prefix+"_"+suffix))
}

func RandomFileName(tmpDir string, prefix string, extension string) string {
suffix, _ := goutils.RandomNumeric(8)
return filepath.Join(tmpDir, prefix+"_"+suffix+extension)
return Abs(filepath.Join(tmpDir, prefix+"_"+suffix+extension))
}
Loading
Loading