Skip to content

Commit c6aa745

Browse files
author
Youen Péron
authored
Merge pull request #35 from CGI-FR/feat-ingress-descriptor-argument
feat(id): add option to change ingress-descriptor filename
2 parents a65beb0 + 966c6bb commit c6aa745

File tree

20 files changed

+193
-126
lines changed

20 files changed

+193
-126
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ Types of changes
1414
- `Fixed` for any bug fixes.
1515
- `Security` in case of vulnerabilities.
1616

17+
## [1.6.0]
18+
19+
- `Added` option to change ingress-descriptor filename
20+
1721
## [1.5.0]
1822

1923
- `Added` update Pimo to v1.8.0

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,11 @@ IngressDescriptor:
135135
name: public.language
136136
```
137137

138+
### `--ingress-descriptor` argument
139+
140+
Ingress descriptor filename is parameterized with the `--ingress-descriptor` argument or its short alias `-i`.
141+
this argument is present for all commands below.
142+
138143
### Display plan
139144

140145
The `display-plan` utilities explain the `lino`'s plan to extract data from database.

cmd/lino/dep_id.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ import (
2424
domain "github.com/cgi-fr/lino/pkg/id"
2525
)
2626

27-
func idStorage() domain.Storage {
28-
return infra.NewMultiStorage(infra.NewYAMLStorage(), infra.NewDOTStorage())
27+
func idStorageFile(filename string) domain.Storage {
28+
return infra.NewMultiStorage(infra.NewYAMLStorage(filename), infra.NewDOTStorage())
2929
}
3030

31-
func idStorageFactory() func(string) domain.Storage {
32-
return func(table string) domain.Storage {
31+
func idStorageFactory() func(string, string) domain.Storage {
32+
return func(table string, filename string) domain.Storage {
3333
if table == "" {
34-
return idStorage()
34+
return idStorageFile(filename)
3535
}
3636
return infra.NewTableStorage(domain.NewTable(table))
3737
}

cmd/lino/main.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,6 @@ func main() {
9797
pprof.StartCPUProfile(f)
9898
defer pprof.StopCPUProfile() */
9999
// CPU profiling code ends here
100-
101100
if err := rootCmd.Execute(); err != nil {
102101
fmt.Println(err)
103102
os.Exit(1)
@@ -166,7 +165,7 @@ func initConfig() {
166165
dataconnector.Inject(dataconnectorStorage(), dataPingerFactory())
167166
relation.Inject(dataconnectorStorage(), relationStorage(), relationExtractorFactory())
168167
table.Inject(dataconnectorStorage(), tableStorage(), tableExtractorFactory())
169-
id.Inject(idStorage(), relationStorage(), idExporter(), idJSONStorage(*os.Stdout))
168+
id.Inject(idStorageFile, relationStorage(), idExporter(), idJSONStorage(*os.Stdout))
170169
pull.Inject(dataconnectorStorage(), relationStorage(), tableStorage(), idStorageFactory(), pullDataSourceFactory(), pullRowExporterFactory(), pullRowReaderFactory(), traceListner(os.Stderr))
171170
push.Inject(dataconnectorStorage(), relationStorage(), tableStorage(), idStorageFactory(), pushDataDestinationFactory(), pushRowIteratorFactory(), pushRowExporterFactory())
172171
}

internal/app/http/cli.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,10 @@ import (
3131

3232
// NewCommand implements the cli http command
3333
func NewCommand(fullName string, err *os.File, out *os.File, in *os.File) *cobra.Command {
34-
var port uint
34+
var (
35+
port uint
36+
ingressDescriptor string
37+
)
3538

3639
cmd := &cobra.Command{
3740
Use: "http",
@@ -46,23 +49,23 @@ func NewCommand(fullName string, err *os.File, out *os.File, in *os.File) *cobra
4649

4750
api.Path("/data/{dataSource}").
4851
Methods(http.MethodGet).
49-
HandlerFunc(pull.Handler)
52+
HandlerFunc(pull.HandlerFactory(ingressDescriptor))
5053

5154
api.Path("/data/{dataDestination}").
5255
Queries("mode", "delete").
53-
HandlerFunc(push.DeleteHandler)
56+
HandlerFunc(push.DeleteHandlerFactory(ingressDescriptor))
5457

5558
api.Path("/data/{dataDestination}").
5659
Queries("mode", "insert").
57-
HandlerFunc(push.InsertHandler)
60+
HandlerFunc(push.InsertHandlerFactory(ingressDescriptor))
5861

5962
api.Path("/data/{dataDestination}").
6063
Queries("mode", "truncate").
61-
HandlerFunc(push.TruncatHandler)
64+
HandlerFunc(push.TruncatHandlerFactory(ingressDescriptor))
6265

6366
api.Path("/data/{dataDestination}").
6467
Methods(http.MethodPost).
65-
HandlerFunc(push.TruncatHandler)
68+
HandlerFunc(push.TruncatHandlerFactory(ingressDescriptor))
6669

6770
http.Handle("/", r)
6871
bind := fmt.Sprintf(":%d", port)
@@ -75,6 +78,7 @@ func NewCommand(fullName string, err *os.File, out *os.File, in *os.File) *cobra
7578
},
7679
}
7780
cmd.Flags().UintVarP(&port, "port", "p", 8000, "HTTP Port to bind")
81+
cmd.Flags().StringVarP(&ingressDescriptor, "ingress-descriptor", "i", "ingress-descriptor.yaml", "Ingress descriptor filename")
7882
cmd.SetOut(out)
7983
cmd.SetErr(err)
8084
cmd.SetIn(in)

internal/app/id/cli.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,16 @@ import (
2828
)
2929

3030
var (
31-
idStorage id.Storage
32-
relStorage relation.Storage
33-
idExporter id.Exporter
34-
idJSONExporter id.Storage
31+
idStorageFactory func(string) id.Storage
32+
relStorage relation.Storage
33+
idExporter id.Exporter
34+
idJSONExporter id.Storage
35+
ingressDescriptor string
3536
)
3637

3738
// Inject dependencies
38-
func Inject(ids id.Storage, rels relation.Storage, ex id.Exporter, jSONEx id.Storage) {
39-
idStorage = ids
39+
func Inject(ids func(string) id.Storage, rels relation.Storage, ex id.Exporter, jSONEx id.Storage) {
40+
idStorageFactory = ids
4041
relStorage = rels
4142
idExporter = ex
4243
idJSONExporter = jSONEx
@@ -57,6 +58,7 @@ func NewCommand(fullName string, err *os.File, out *os.File, in *os.File) *cobra
5758
cmd.AddCommand(newSetStartTableCommand(fullName, err, out, in))
5859
cmd.AddCommand(newSetChildLookupCommand(fullName, err, out, in))
5960
cmd.AddCommand(newSetParentLookupCommand(fullName, err, out, in))
61+
cmd.PersistentFlags().StringVarP(&ingressDescriptor, "ingress-descriptor", "i", "ingress-descriptor.yaml", "Ingress descriptor filename")
6062
cmd.SetOut(out)
6163
cmd.SetErr(err)
6264
cmd.SetIn(in)

internal/app/id/create.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ func newCreateCommand(fullName string, err *os.File, out *os.File, in *os.File)
4545

4646
reader := infra.NewRelationReader(relations)
4747

48-
e := id.Create(table, reader, idStorage)
48+
e := id.Create(table, reader, idStorageFactory(ingressDescriptor))
4949
if e != nil {
5050
fmt.Fprintln(err, e.Description)
5151
os.Exit(1)

internal/app/id/displayplan.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ func newDisplayPlanCommand(fullName string, err *os.File, out *os.File, in *os.F
3434
Example: fmt.Sprintf(" %[1]s id display-plan", fullName),
3535
Args: cobra.NoArgs,
3636
Run: func(cmd *cobra.Command, args []string) {
37-
result, e := id.GetPullerPlan(idStorage)
37+
result, e := id.GetPullerPlan(idStorageFactory(ingressDescriptor))
3838
if e != nil {
3939
fmt.Fprintln(err, e.Description)
4040
os.Exit(1)

internal/app/id/export.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func newExportCommand(fullName string, err *os.File, out *os.File, in *os.File)
3333
Example: fmt.Sprintf(" %[1]s id export", fullName),
3434
Args: cobra.NoArgs,
3535
Run: func(cmd *cobra.Command, args []string) {
36-
id, e := idStorage.Read()
36+
id, e := idStorageFactory(ingressDescriptor).Read()
3737
if e != nil {
3838
fmt.Fprintln(err, e.Description)
3939
os.Exit(1)

internal/app/id/set_child_lookup.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func newSetChildLookupCommand(fullName string, err *os.File, out *os.File, in *o
4141
os.Exit(1)
4242
}
4343

44-
e := id.SetChildLookup(relation, flag, idStorage)
44+
e := id.SetChildLookup(relation, flag, idStorageFactory(ingressDescriptor))
4545
if e != nil {
4646
fmt.Fprintln(err, e.Description)
4747
os.Exit(1)

0 commit comments

Comments
 (0)