Mercurial > gemma
annotate pkg/controllers/importconfig.go @ 4550:aa2d0006e742 iso-areas
Write iso lines between classes to SVG for debugging.
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 30 Sep 2019 16:34:55 +0200 |
parents | 4394daeea96a |
children | 7b6a62d4117e |
rev | line source |
---|---|
1582
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 // without warranty, see README.md and license for details. |
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 // |
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 // |
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 // Copyright (C) 2018 by via donau |
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 // Software engineering by Intevation GmbH |
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 // |
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 // Author(s): |
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 |
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 package controllers |
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import ( |
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 "database/sql" |
2051
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
18 "encoding/json" |
2046
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
19 "fmt" |
1582
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 "net/http" |
2045
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
21 "strconv" |
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
22 |
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
23 "github.com/gorilla/mux" |
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
24 |
2051
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
25 "gemma.intevation.de/gemma/pkg/auth" |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
26 "gemma.intevation.de/gemma/pkg/common" |
2045
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
27 "gemma.intevation.de/gemma/pkg/imports" |
2050
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
28 "gemma.intevation.de/gemma/pkg/scheduler" |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
29 |
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
30 mw "gemma.intevation.de/gemma/pkg/middleware" |
1583
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
31 ) |
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
32 |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
33 func runImportConfig(req *http.Request) (jr mw.JSONResult, err error) { |
1730
7c54babe10f7
Configured imports: Added GET /imports/config/{id:[0-9]+}/run" to run a configured import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1727
diff
changeset
|
34 |
2045
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
35 id, _ := strconv.ParseInt(mux.Vars(req)["id"], 10, 64) |
1730
7c54babe10f7
Configured imports: Added GET /imports/config/{id:[0-9]+}/run" to run a configured import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1727
diff
changeset
|
36 |
2045
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
37 ctx := req.Context() |
1748
c11807dc6940
Comfigured imports: Run enqueing of configured imports if triggered by REST with the database connection of the logged in user.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1739
diff
changeset
|
38 |
2045
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
39 var jobID int64 |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
40 if jobID, err = imports.RunConfiguredImportContext(ctx, mw.JSONConn(req), id); err != nil { |
2045
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
41 return |
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
42 } |
1730
7c54babe10f7
Configured imports: Added GET /imports/config/{id:[0-9]+}/run" to run a configured import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1727
diff
changeset
|
43 |
2045
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
44 var result = struct { |
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
45 ID int64 `json:"id"` |
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
46 }{ |
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
47 ID: jobID, |
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
48 } |
1730
7c54babe10f7
Configured imports: Added GET /imports/config/{id:[0-9]+}/run" to run a configured import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1727
diff
changeset
|
49 |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
50 jr = mw.JSONResult{ |
2045
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
51 Code: http.StatusCreated, |
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
52 Result: &result, |
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
53 } |
1730
7c54babe10f7
Configured imports: Added GET /imports/config/{id:[0-9]+}/run" to run a configured import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1727
diff
changeset
|
54 return |
7c54babe10f7
Configured imports: Added GET /imports/config/{id:[0-9]+}/run" to run a configured import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1727
diff
changeset
|
55 } |
7c54babe10f7
Configured imports: Added GET /imports/config/{id:[0-9]+}/run" to run a configured import.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1727
diff
changeset
|
56 |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
57 func modifyImportConfig(req *http.Request) (jr mw.JSONResult, err error) { |
1592
c12cec1d7692
Added PATCH /imports/scheduler/{id:[0-9]+} to modify a single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1591
diff
changeset
|
58 |
2052
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
59 ctx := req.Context() |
1592
c12cec1d7692
Added PATCH /imports/scheduler/{id:[0-9]+} to modify a single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1591
diff
changeset
|
60 |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
61 raw := mw.JSONInput(req).(*json.RawMessage) |
1592
c12cec1d7692
Added PATCH /imports/scheduler/{id:[0-9]+} to modify a single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1591
diff
changeset
|
62 |
2052
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
63 id, _ := strconv.ParseInt(mux.Vars(req)["id"], 10, 64) |
2042
d29ac997eb34
This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2016
diff
changeset
|
64 |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
65 conn := mw.JSONConn(req) |
4242
1458c9b0fdaa
Made the sql.Conn in function accessible via the context of the request.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3975
diff
changeset
|
66 |
2052
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
67 var pc *imports.PersistentConfig |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
68 pc, err = imports.LoadPersistentConfigContext(ctx, conn, id) |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
69 switch { |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
70 case err == sql.ErrNoRows: |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
71 err = mw.JSONError{ |
2052
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
72 Code: http.StatusNotFound, |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
73 Message: fmt.Sprintf("No configuration %d found", id), |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
74 } |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
75 return |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
76 case err != nil: |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
77 return |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
78 } |
2042
d29ac997eb34
This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2016
diff
changeset
|
79 |
2052
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
80 kind := imports.JobKind(pc.Kind) |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
81 ctor := imports.ImportModelForJobKind(kind) |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
82 if ctor == nil { |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
83 err = mw.JSONError{ |
2052
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
84 Code: http.StatusInternalServerError, |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
85 Message: fmt.Sprintf("No constructor for kind '%s' found", pc.Kind), |
1704
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
86 } |
2052
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
87 return |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
88 } |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
89 config := ctor() |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
90 if err = json.Unmarshal(*raw, config); err != nil { |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
91 return |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
92 } |
2042
d29ac997eb34
This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2016
diff
changeset
|
93 |
2052
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
94 _, oldCron := pc.Attributes.Get("cron") |
2042
d29ac997eb34
This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2016
diff
changeset
|
95 |
2052
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
96 session, _ := auth.GetSession(req) |
3552
ffc8fb059d1a
refactor password persistence for import configurations.
Thomas Junk <thomas.junk@intevation.de>
parents:
3549
diff
changeset
|
97 // When a password is stored it doesn't get retransmitted to the client |
ffc8fb059d1a
refactor password persistence for import configurations.
Thomas Junk <thomas.junk@intevation.de>
parents:
3549
diff
changeset
|
98 // in order to prevent password leakage |
ffc8fb059d1a
refactor password persistence for import configurations.
Thomas Junk <thomas.junk@intevation.de>
parents:
3549
diff
changeset
|
99 // When the user changes the import configuration without a new password |
ffc8fb059d1a
refactor password persistence for import configurations.
Thomas Junk <thomas.junk@intevation.de>
parents:
3549
diff
changeset
|
100 // the old password should be conserved |
3554
efa468653d48
only write password attribute, when available previous
Thomas Junk <thomas.junk@intevation.de>
parents:
3552
diff
changeset
|
101 oldPasswd, ok := pc.Attributes["password"] |
2052
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
102 pc.User = session.User |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
103 pc.Attributes = common.Attributes{} |
3975
8af156928a2d
Removed stupid bool == true comparision.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3554
diff
changeset
|
104 if ok { |
3554
efa468653d48
only write password attribute, when available previous
Thomas Junk <thomas.junk@intevation.de>
parents:
3552
diff
changeset
|
105 pc.Attributes["password"] = oldPasswd |
efa468653d48
only write password attribute, when available previous
Thomas Junk <thomas.junk@intevation.de>
parents:
3552
diff
changeset
|
106 } |
3552
ffc8fb059d1a
refactor password persistence for import configurations.
Thomas Junk <thomas.junk@intevation.de>
parents:
3549
diff
changeset
|
107 pc.Attributes.Marshal(config) // Marshal only overwrites keys present in config |
2052
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
108 cron, newCron := pc.Attributes.Get("cron") |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
109 |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
110 var tx *sql.Tx |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
111 if tx, err = conn.BeginTx(ctx, nil); err != nil { |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
112 return |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
113 } |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
114 defer tx.Rollback() |
1592
c12cec1d7692
Added PATCH /imports/scheduler/{id:[0-9]+} to modify a single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1591
diff
changeset
|
115 |
2052
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
116 if err = pc.UpdateContext(ctx, tx); err != nil { |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
117 return |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
118 } |
2042
d29ac997eb34
This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2016
diff
changeset
|
119 |
2052
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
120 if oldCron { |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
121 scheduler.UnbindByID(id) |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
122 } |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
123 |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
124 if newCron { |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
125 if err = scheduler.BindAction( |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
126 string(pc.Kind), |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
127 cron, |
2042
d29ac997eb34
This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2016
diff
changeset
|
128 id, |
1592
c12cec1d7692
Added PATCH /imports/scheduler/{id:[0-9]+} to modify a single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1591
diff
changeset
|
129 ); err != nil { |
c12cec1d7692
Added PATCH /imports/scheduler/{id:[0-9]+} to modify a single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1591
diff
changeset
|
130 return |
c12cec1d7692
Added PATCH /imports/scheduler/{id:[0-9]+} to modify a single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1591
diff
changeset
|
131 } |
2052
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
132 } |
1592
c12cec1d7692
Added PATCH /imports/scheduler/{id:[0-9]+} to modify a single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1591
diff
changeset
|
133 |
2052
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
134 if err = tx.Commit(); err != nil { |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
135 return |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
136 } |
1592
c12cec1d7692
Added PATCH /imports/scheduler/{id:[0-9]+} to modify a single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1591
diff
changeset
|
137 |
2052
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
138 var result = struct { |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
139 ID int64 `json:"id"` |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
140 }{ |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
141 ID: id, |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
142 } |
1592
c12cec1d7692
Added PATCH /imports/scheduler/{id:[0-9]+} to modify a single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1591
diff
changeset
|
143 |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
144 jr = mw.JSONResult{Result: &result} |
1592
c12cec1d7692
Added PATCH /imports/scheduler/{id:[0-9]+} to modify a single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1591
diff
changeset
|
145 return |
c12cec1d7692
Added PATCH /imports/scheduler/{id:[0-9]+} to modify a single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1591
diff
changeset
|
146 } |
c12cec1d7692
Added PATCH /imports/scheduler/{id:[0-9]+} to modify a single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1591
diff
changeset
|
147 |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
148 func infoImportConfig(req *http.Request) (jr mw.JSONResult, err error) { |
1591
2d53065c95af
Added GET /imports/scheduler/{id:[0-9]+} to show infos about single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1590
diff
changeset
|
149 |
2046
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
150 ctx := req.Context() |
1591
2d53065c95af
Added GET /imports/scheduler/{id:[0-9]+} to show infos about single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1590
diff
changeset
|
151 |
2046
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
152 id, _ := strconv.ParseInt(mux.Vars(req)["id"], 10, 64) |
1591
2d53065c95af
Added GET /imports/scheduler/{id:[0-9]+} to show infos about single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1590
diff
changeset
|
153 |
2046
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
154 var cfg *imports.PersistentConfig |
1591
2d53065c95af
Added GET /imports/scheduler/{id:[0-9]+} to show infos about single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1590
diff
changeset
|
155 |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
156 cfg, err = imports.LoadPersistentConfigContext(ctx, mw.JSONConn(req), id) |
2046
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
157 switch { |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
158 case err != nil: |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
159 return |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
160 case cfg == nil: |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
161 err = mw.JSONError{ |
2046
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
162 Code: http.StatusNotFound, |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
163 Message: fmt.Sprintf("No schedule %d found", id), |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
164 } |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
165 return |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
166 } |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
167 |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
168 kind := imports.JobKind(cfg.Kind) |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
169 |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
170 ctor := imports.ImportModelForJobKind(kind) |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
171 if ctor == nil { |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
172 err = mw.JSONError{ |
2046
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
173 Code: http.StatusInternalServerError, |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
174 Message: fmt.Sprintf("No constructor for kind '%s' found", cfg.Kind), |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
175 } |
2052
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
176 return |
2046
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
177 } |
2047
78002c5e838c
Imports: Code simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2046
diff
changeset
|
178 |
3515
c64c47ff2ab1
import: fix for passwordleakage. No passwords are received/sent if configuration is edited.
Thomas Junk <thomas.junk@intevation.de>
parents:
2052
diff
changeset
|
179 // Remove `password` from the attributes to be delivered to the client. |
c64c47ff2ab1
import: fix for passwordleakage. No passwords are received/sent if configuration is edited.
Thomas Junk <thomas.junk@intevation.de>
parents:
2052
diff
changeset
|
180 // Even a priviledged user shall not be able to see the password. |
c64c47ff2ab1
import: fix for passwordleakage. No passwords are received/sent if configuration is edited.
Thomas Junk <thomas.junk@intevation.de>
parents:
2052
diff
changeset
|
181 // (See config.ListAllPersistentConfigurationsContext() for the other |
c64c47ff2ab1
import: fix for passwordleakage. No passwords are received/sent if configuration is edited.
Thomas Junk <thomas.junk@intevation.de>
parents:
2052
diff
changeset
|
182 // place where this is done.) |
c64c47ff2ab1
import: fix for passwordleakage. No passwords are received/sent if configuration is edited.
Thomas Junk <thomas.junk@intevation.de>
parents:
2052
diff
changeset
|
183 filteredAttributes := make(common.Attributes) |
c64c47ff2ab1
import: fix for passwordleakage. No passwords are received/sent if configuration is edited.
Thomas Junk <thomas.junk@intevation.de>
parents:
2052
diff
changeset
|
184 for key, value := range cfg.Attributes { |
c64c47ff2ab1
import: fix for passwordleakage. No passwords are received/sent if configuration is edited.
Thomas Junk <thomas.junk@intevation.de>
parents:
2052
diff
changeset
|
185 if key != "password" { |
c64c47ff2ab1
import: fix for passwordleakage. No passwords are received/sent if configuration is edited.
Thomas Junk <thomas.junk@intevation.de>
parents:
2052
diff
changeset
|
186 filteredAttributes[key] = value |
c64c47ff2ab1
import: fix for passwordleakage. No passwords are received/sent if configuration is edited.
Thomas Junk <thomas.junk@intevation.de>
parents:
2052
diff
changeset
|
187 } |
c64c47ff2ab1
import: fix for passwordleakage. No passwords are received/sent if configuration is edited.
Thomas Junk <thomas.junk@intevation.de>
parents:
2052
diff
changeset
|
188 } |
2046
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
189 |
3515
c64c47ff2ab1
import: fix for passwordleakage. No passwords are received/sent if configuration is edited.
Thomas Junk <thomas.junk@intevation.de>
parents:
2052
diff
changeset
|
190 what := ctor() |
c64c47ff2ab1
import: fix for passwordleakage. No passwords are received/sent if configuration is edited.
Thomas Junk <thomas.junk@intevation.de>
parents:
2052
diff
changeset
|
191 if err = filteredAttributes.Unmarshal(what); err != nil { |
2047
78002c5e838c
Imports: Code simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2046
diff
changeset
|
192 return |
2046
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
193 } |
1591
2d53065c95af
Added GET /imports/scheduler/{id:[0-9]+} to show infos about single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1590
diff
changeset
|
194 |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
195 jr = mw.JSONResult{Result: &imports.ImportConfigOut{ |
2046
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
196 ID: id, |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
197 Kind: imports.ImportKind(cfg.Kind), |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
198 Config: what, |
725884a4c89a
Imports: Re-enabled /imports/config/{id} GET-
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
199 }} |
1591
2d53065c95af
Added GET /imports/scheduler/{id:[0-9]+} to show infos about single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1590
diff
changeset
|
200 return |
2d53065c95af
Added GET /imports/scheduler/{id:[0-9]+} to show infos about single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1590
diff
changeset
|
201 } |
2d53065c95af
Added GET /imports/scheduler/{id:[0-9]+} to show infos about single import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1590
diff
changeset
|
202 |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
203 func deleteImportConfig(req *http.Request) (jr mw.JSONResult, err error) { |
1590
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1589
diff
changeset
|
204 |
2050
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
205 ctx := req.Context() |
1590
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1589
diff
changeset
|
206 |
2050
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
207 id, _ := strconv.ParseInt(mux.Vars(req)["id"], 10, 64) |
1590
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1589
diff
changeset
|
208 |
2050
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
209 var tx *sql.Tx |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
210 if tx, err = mw.JSONConn(req).BeginTx(ctx, nil); err != nil { |
2050
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
211 return |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
212 } |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
213 defer tx.Rollback() |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
214 |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
215 err = imports.DeletePersistentConfigurationContext( |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
216 ctx, |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
217 tx, |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
218 id, |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
219 ) |
1704
897d4d8316ad
Import configuration: Made extra attributes updatable, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1702
diff
changeset
|
220 |
2050
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
221 switch { |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
222 case err == sql.ErrNoRows: |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
223 err = mw.JSONError{ |
2050
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
224 Code: http.StatusNotFound, |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
225 Message: fmt.Sprintf("No configuration %d found", id), |
2049
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2048
diff
changeset
|
226 } |
2050
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
227 return |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
228 case err != nil: |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
229 return |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
230 } |
2042
d29ac997eb34
This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2016
diff
changeset
|
231 |
2050
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
232 // Remove from running scheduler. |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
233 scheduler.UnbindByID(id) |
2049
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2048
diff
changeset
|
234 |
2050
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
235 if err = tx.Commit(); err != nil { |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
236 return |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
237 } |
1590
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1589
diff
changeset
|
238 |
2050
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
239 var result = struct { |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
240 ID int64 `json:"id"` |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
241 }{ |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
242 ID: id, |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
243 } |
1590
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1589
diff
changeset
|
244 |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
245 jr = mw.JSONResult{Result: &result} |
2042
d29ac997eb34
This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2016
diff
changeset
|
246 |
1590
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1589
diff
changeset
|
247 return |
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1589
diff
changeset
|
248 } |
2fdd8e57542d
Added DELETE /imports/scheduler/{id:[0-9]+} to delete a schedule from the scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1589
diff
changeset
|
249 |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
250 func addImportConfig(req *http.Request) (jr mw.JSONResult, err error) { |
1589
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
251 |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
252 cfg := mw.JSONInput(req).(*imports.ImportConfigIn) |
1589
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
253 |
2051
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
254 kind := imports.JobKind(cfg.Kind) |
1589
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
255 |
2051
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
256 ctor := imports.ImportModelForJobKind(kind) |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
257 if ctor == nil { |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
258 err = mw.JSONError{ |
2051
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
259 Code: http.StatusBadRequest, |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
260 Message: fmt.Sprintf("No kind %s found", string(cfg.Kind)), |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
261 } |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
262 return |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
263 } |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
264 config := ctor() |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
265 if err = json.Unmarshal(cfg.Config, config); err != nil { |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
266 return |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
267 } |
1589
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
268 |
2051
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
269 session, _ := auth.GetSession(req) |
1589
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
270 |
2051
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
271 pc := imports.PersistentConfig{ |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
272 User: session.User, |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
273 Kind: string(cfg.Kind), |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
274 Attributes: common.Attributes{}, |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
275 } |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
276 pc.Attributes.Marshal(config) |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
277 |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
278 ctx := req.Context() |
1589
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
279 |
2051
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
280 var tx *sql.Tx |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
281 if tx, err = mw.JSONConn(req).BeginTx(ctx, nil); err != nil { |
2051
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
282 return |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
283 } |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
284 defer tx.Rollback() |
1702
49b89575ab31
Import configuration: [WIP] Added table for extra configuration attributes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1654
diff
changeset
|
285 |
2051
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
286 var id int64 |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
287 if id, err = pc.StoreContext(ctx, tx); err != nil { |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
288 return |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
289 } |
2042
d29ac997eb34
This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2016
diff
changeset
|
290 |
2051
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
291 // Need to start a scheduler job right away? |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
292 if cron, ok := pc.Attributes.Get("cron"); ok { |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
293 if err = scheduler.BindAction(string(cfg.Kind), cron, id); err != nil { |
1589
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
294 return |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
295 } |
2051
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
296 } |
1589
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
297 |
2051
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
298 if err = tx.Commit(); err != nil { |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
299 scheduler.UnbindByID(id) |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
300 return |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
301 } |
1589
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
302 |
2051
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
303 var result = struct { |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
304 ID int64 `json:"id"` |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
305 }{ |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
306 ID: id, |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
307 } |
1589
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
308 |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
309 jr = mw.JSONResult{ |
2051
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
310 Code: http.StatusCreated, |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
311 Result: &result, |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
312 } |
1589
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
313 return |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
314 } |
e0bd82f6ee14
Added PUT /api/imports/scheduler to add a import configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1583
diff
changeset
|
315 |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
316 func listImportConfigs(req *http.Request) (jr mw.JSONResult, err error) { |
1583
caedd9b176f2
Added GET to /api/imports/scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1582
diff
changeset
|
317 |
2049
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2048
diff
changeset
|
318 ctx := req.Context() |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2048
diff
changeset
|
319 configs := []*imports.ImportConfigOut{} |
2042
d29ac997eb34
This breaks this branch!!!! Starting to remove the old persistent layer for configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2016
diff
changeset
|
320 |
2049
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2048
diff
changeset
|
321 if err = imports.ListAllPersistentConfigurationsContext( |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
322 ctx, mw.JSONConn(req), |
2049
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2048
diff
changeset
|
323 func(config *imports.ImportConfigOut) error { |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2048
diff
changeset
|
324 configs = append(configs, config) |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2048
diff
changeset
|
325 return nil |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2048
diff
changeset
|
326 }, |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2048
diff
changeset
|
327 ); err != nil { |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2048
diff
changeset
|
328 return |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2048
diff
changeset
|
329 } |
4244
4394daeea96a
Moved JSONHandler into middleware package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4243
diff
changeset
|
330 jr = mw.JSONResult{Result: configs} |
1582
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
331 return |
dc727824183a
Started with REST API for scheduler.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
332 } |