Skip to content

Commit

Permalink
fix: repo update command is missing option for git and image
Browse files Browse the repository at this point in the history
  • Loading branch information
KunalSin9h committed Mar 11, 2024
1 parent a519873 commit 8f39662
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 23 deletions.
24 changes: 10 additions & 14 deletions cli_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ meltcd login --show-token
1. Create a new `Application` [DONE]

```bash
meltcd app create <app-name> --repo <repo-url> --path <path-to-spec>
meltcd app create <app-name> --repo <repo> --path <path-to-spec>
```

2. Create a new `Application` with file [DONE]
Expand All @@ -24,7 +24,7 @@ meltcd app create --file <path-to-file>
3. Update existing `Application` [DONE]

```bash
meltcd app update <app-name> --repo <repo-url> --path <path-to-spec>
meltcd app update <app-name> --repo <repo> --path <path-to-spec>

# Or using file

Expand Down Expand Up @@ -81,9 +81,13 @@ meltcd app rm <app-name>
1. Add a private repository auth credentials [DONE]

```bash
meltcd repo add <repo-url> --username <username> --password <password>
meltcd repo add <repo> --git --username <username> --password <password>
```

Options
`--git` if repo is the git repository
`--image` if repo is Container image

2. List all added repositories [DONE]

```bash
Expand All @@ -97,23 +101,15 @@ meltcd repo list
3. Remove a repository [DONE]

```bash
meltcd repo rm <repo-url>
meltcd repo rm <repo>

# or

meltcd repo remove <repo-url>
meltcd repo remove <repo>
```

4. Update a repository [DONE]

```bash
meltcd repo update <repo-url> --username <username> --password <password>
```

# Private Image

1. Add a image auth credentials [TODO]

```bash
meltcd image add <image-name> --username <username> --password <password>
meltcd repo update <repo> --git --username <username> --password <password>
```
2 changes: 2 additions & 0 deletions cmd/meltcd/meltcd.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ func NewCLI() *cobra.Command {
RunE: updatePrivateRepo,
}

repoUpdateCmd.Flags().Bool("git", false, "if private repo is a git repository")
repoUpdateCmd.Flags().Bool("image", false, "if private repo is a docker image")
repoUpdateCmd.Flags().String("username", "", "username for basic auth")
repoUpdateCmd.MarkFlagRequired("username")
repoUpdateCmd.Flags().String("password", "", "password for basic auth")
Expand Down
18 changes: 15 additions & 3 deletions cmd/meltcd/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,14 +169,26 @@ func removePrivateRepo(_ *cobra.Command, args []string) error {
}

func updatePrivateRepo(cmd *cobra.Command, args []string) error {
repoURL := args[0]
repoURL, _ = strings.CutSuffix(repoURL, "/")
repoName := args[0]

git, _ := cmd.Flags().GetBool("git")
image, _ := cmd.Flags().GetBool("image")
username, _ := cmd.Flags().GetString("username")
password, _ := cmd.Flags().GetString("password")

gitRepo, imageRepo := "", ""

if git {
gitRepo = repoName
}

if image {
imageRepo = repoName
}

payload := repo.PrivateRepoDetails{
URL: repoURL,
URL: gitRepo,
ImageRef: imageRepo,
Username: username,
Password: password,
}
Expand Down
6 changes: 4 additions & 2 deletions internal/core/repository/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ import (
"errors"
)

func Update(url, username, password string) error {
repo, found := FindRepo(url)
func Update(url, image, username, password string) error {
// eight url is empty or image is empty
// so combining them will give the name
repo, found := FindRepo(url + image)
if !found {
return errors.New("repository does not exists")
}
Expand Down
6 changes: 2 additions & 4 deletions server/api/repo/repo.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,15 +154,13 @@ func Update(c *fiber.Ctx) error { // nolint:all
})
}

if payload.URL == "" || payload.Username == "" || payload.Password == "" {
if (payload.URL == "" && payload.ImageRef == "") || payload.Username == "" || payload.Password == "" {
return c.Status(fiber.StatusBadRequest).JSON(app.GlobalResponse{
Message: "missing url, username or password in request body",
})
}

url, _ := strings.CutSuffix(payload.URL, "/")

if err := repository.Update(url, payload.Username, payload.Password); err != nil {
if err := repository.Update(payload.URL, payload.ImageRef, payload.Username, payload.Password); err != nil {
return c.Status(fiber.StatusInternalServerError).JSON(app.GlobalResponse{
Message: err.Error(),
})
Expand Down

0 comments on commit 8f39662

Please sign in to comment.