Skip to content

Commit

Permalink
Use new api name
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszo committed Jan 17, 2025
1 parent 0cdbec2 commit 464ab4b
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 31 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ require (
github.com/gofrs/uuid v4.3.0+incompatible
github.com/gorilla/websocket v1.5.0
github.com/iancoleman/strcase v0.2.0
github.com/koyeb/koyeb-api-client-go v0.0.0-20250106150959-2940e5613765
github.com/koyeb/koyeb-api-client-go v0.0.0-20250117143439-03648cc5a823
github.com/logrusorgru/aurora v2.0.3+incompatible
github.com/manifoldco/promptui v0.9.0
github.com/mitchellh/go-homedir v1.1.0
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,8 @@ github.com/koyeb/koyeb-api-client-go v0.0.0-20241206143543-39fbd0d0bf5e h1:/pSED
github.com/koyeb/koyeb-api-client-go v0.0.0-20241206143543-39fbd0d0bf5e/go.mod h1:+oQfFj2WL3gi9Pb+UHbob4D7xaT52mPfKyH1UvWa4PQ=
github.com/koyeb/koyeb-api-client-go v0.0.0-20250106150959-2940e5613765 h1:OaJezhu0iuR0XN6y5Sxc6uARWyPx1WG1ZjBgVgG7jvw=
github.com/koyeb/koyeb-api-client-go v0.0.0-20250106150959-2940e5613765/go.mod h1:+oQfFj2WL3gi9Pb+UHbob4D7xaT52mPfKyH1UvWa4PQ=
github.com/koyeb/koyeb-api-client-go v0.0.0-20250117143439-03648cc5a823 h1:icM+7zADUhhsv1DSXVHdT3UusXWOsZ25aolFPmhgPiU=
github.com/koyeb/koyeb-api-client-go v0.0.0-20250117143439-03648cc5a823/go.mod h1:+oQfFj2WL3gi9Pb+UHbob4D7xaT52mPfKyH1UvWa4PQ=
github.com/kr/fs v0.1.0/go.mod h1:FFnZGqtBN9Gxj7eW1uZ42v5BccTP0vu6NEaFoC2HwRg=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo=
github.com/kr/pretty v0.2.1/go.mod h1:ipq/a2n7PKx3OHsz4KJII5eveXtPO4qwEXGdVfWzfnI=
Expand Down
44 changes: 22 additions & 22 deletions pkg/koyeb/flags_list/file_mounts.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ type FlagFile struct {
content string
}

func GetNewFilestListFromFlags() func(values []string) ([]Flag[koyeb.File], error) {
return func(values []string) ([]Flag[koyeb.File], error) {
ret := make([]Flag[koyeb.File], 0, len(values))
func GetNewConfigFilestListFromFlags() func(values []string) ([]Flag[koyeb.ConfigFile], error) {
return func(values []string) ([]Flag[koyeb.ConfigFile], error) {
ret := make([]Flag[koyeb.ConfigFile], 0, len(values))

for _, value := range values {
hc := &FlagFile{BaseFlag: BaseFlag{cliValue: value}}
Expand All @@ -29,13 +29,13 @@ func GetNewFilestListFromFlags() func(values []string) ([]Flag[koyeb.File], erro
if len(components) > 1 {
return nil, &kerrors.CLIError{
What: "Error while configuring the service",
Why: fmt.Sprintf("unable to parse the file flag value \"%s\"", hc.cliValue),
Why: fmt.Sprintf("unable to parse the config-file flag value \"%s\"", hc.cliValue),
Additional: []string{
"To remove a mounted file from the service, prefix the path with '!', e.g. '!path'",
"To remove a mounted config file from the service, prefix the path with '!', e.g. '!path'",
"The source should not be specified to remove it from the service",
},
Orig: nil,
Solution: "Fix the file flag value and try again",
Solution: "Fix the config-file flag value and try again",
}
}
hc.markedForDeletion = true
Expand All @@ -44,13 +44,13 @@ func GetNewFilestListFromFlags() func(values []string) ([]Flag[koyeb.File], erro
if len(components) != 2 && len(components) != 3 {
return nil, &kerrors.CLIError{
What: "Error while configuring the service",
Why: fmt.Sprintf("unable to parse the file flag value \"%s\"", hc.cliValue),
Why: fmt.Sprintf("unable to parse the confi-file flag value \"%s\"", hc.cliValue),
Additional: []string{
"File flag value must be specified as SOURCE:PATH[:PERMISSIONS]",
"To remove a mounted file from the service, prefix the path with '!', e.g. '!path'",
"Config file flag value must be specified as SOURCE:PATH[:PERMISSIONS]",
"To remove a mounted config file from the service, prefix the path with '!', e.g. '!path'",
},
Orig: nil,
Solution: "Fix the file flag value and try again",
Solution: "Fix the config-file flag value and try again",
}
}
hc.path = components[1]
Expand All @@ -60,11 +60,11 @@ func GetNewFilestListFromFlags() func(values []string) ([]Flag[koyeb.File], erro
What: "Error while configuring the service",
Why: fmt.Sprintf(" Unable to locate file at \"%s\"", path),
Additional: []string{
"File flag value must be specified as SOURCE:PATH[:PERMISSIONS]",
"To remove a mounted file from the service, prefix the path with '!', e.g. '!path'",
"Config file flag value must be specified as SOURCE:PATH[:PERMISSIONS]",
"To remove a mounted config file from the service, prefix the path with '!', e.g. '!path'",
},
Orig: nil,
Solution: "Fix the file flag value and try again",
Solution: "Fix the config-file flag value and try again",
}
}
data, err := os.ReadFile(path)
Expand All @@ -73,11 +73,11 @@ func GetNewFilestListFromFlags() func(values []string) ([]Flag[koyeb.File], erro
What: "Error while configuring the service",
Why: fmt.Sprintf("unable to read the file \"%s\"", path),
Additional: []string{
"File flag value must be specified as SOURCE:PATH[:PERMISSIONS]",
"To remove a file mount from the service, prefix it with '!', e.g. '!path'",
"Config file flag value must be specified as SOURCE:PATH[:PERMISSIONS]",
"To remove a config file mount from the service, prefix it with '!', e.g. '!path'",
},
Orig: nil,
Solution: "Fix the file flag value and try again",
Solution: "Fix the config-file flag value and try again",
}
}
hc.content = string(data)
Expand All @@ -92,10 +92,10 @@ func GetNewFilestListFromFlags() func(values []string) ([]Flag[koyeb.File], erro
Why: fmt.Sprintf("unable to parse the permissions \"%s\"", permissions),
Additional: []string{
"File mount permission must be specified as SOURCE:PATH:PERMISSIONS and in format like 0644",
"To remove a file mount from the service, prefix it with '!', e.g. '!path'",
"To remove a config file mount from the service, prefix it with '!', e.g. '!path'",
},
Orig: nil,
Solution: "Fix the permissions in file flag value and try again",
Solution: "Fix the permissions in config-file flag value and try again",
}
}
hc.permissions = permissions
Expand All @@ -106,18 +106,18 @@ func GetNewFilestListFromFlags() func(values []string) ([]Flag[koyeb.File], erro
}
}

func (f *FlagFile) IsEqualTo(hc koyeb.File) bool {
func (f *FlagFile) IsEqualTo(hc koyeb.ConfigFile) bool {
return hc.GetPath() == f.path
}

func (f *FlagFile) UpdateItem(hc *koyeb.File) {
func (f *FlagFile) UpdateItem(hc *koyeb.ConfigFile) {
hc.Content = &f.content
hc.Path = &f.path
hc.Permissions = &f.permissions
}

func (f *FlagFile) CreateNewItem() *koyeb.File{
item := koyeb.NewFileWithDefaults()
func (f *FlagFile) CreateNewItem() *koyeb.ConfigFile{
item := koyeb.NewConfigFileWithDefaults()
f.UpdateItem(item)
return item
}
17 changes: 9 additions & 8 deletions pkg/koyeb/services.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,10 +378,11 @@ func (h *ServiceHandler) addServiceDefinitionFlagsForAllSources(flags *pflag.Fla
"To delete a volume, use !VOLUME, for example --volume '!myvolume'\n",
)
flags.StringSlice(
"file",
"config-file",
nil,
"Mount a copy of local file as a file in the service container using the format LOCAL_FILE:PATH:[PERMISSIONS] for example --file /etc/data.yaml:/etc/data.yaml:0644\n"+
"To delete a file mount, use !PATH, for example --file !/etc/data.yaml\n",
"Mount a copy of local file as a file in the service container using the format LOCAL_FILE:PATH:[PERMISSIONS]\n"+
"for example --config-file /etc/data.yaml:/etc/data.yaml:0644\n"+
"To delete a file mount, use !PATH, for example --config-file !/etc/data.yaml\n",
)

// Configure aliases: for example, allow user to use --port instead of --ports
Expand Down Expand Up @@ -556,11 +557,11 @@ func (h *ServiceHandler) parseServiceDefinitionFlags(ctx *CLIContext, flags *pfl
}
definition.SetVolumes(volumes)

files, err := h.parseFiles(ctx, flags, definition.Files)
files, err := h.parseConfigFiles(ctx, flags, definition.ConfigFiles)
if err != nil {
return err
}
definition.SetFiles(files)
definition.SetConfigFiles(files)

return nil
}
Expand Down Expand Up @@ -1754,9 +1755,9 @@ func (h *ServiceHandler) parseVolumes(ctx *CLIContext, flags *pflag.FlagSet, cur
return parseListFlags("volumes", flags_list.GetNewVolumeListFromFlags(wrappedResolveVolumeId), flags, currentVolumes)
}

// Parse --file
func (h *ServiceHandler) parseFiles(ctx *CLIContext, flags *pflag.FlagSet, currentFiles []koyeb.File) ([]koyeb.File, error) {
return parseListFlags("file", flags_list.GetNewFilestListFromFlags(), flags, currentFiles)
// Parse --config-file
func (h *ServiceHandler) parseConfigFiles(ctx *CLIContext, flags *pflag.FlagSet, currentFiles []koyeb.ConfigFile) ([]koyeb.ConfigFile, error) {
return parseListFlags("config-file", flags_list.GetNewConfigFilestListFromFlags(), flags, currentFiles)
}

// DeploymentStrategy is a type alias for koyeb.DeploymentStrategyType which implements the pflag.Value interface.
Expand Down

0 comments on commit 464ab4b

Please sign in to comment.