Mercurial > gemma
annotate pkg/imports/config.go @ 4484:819eafe60f41
Merged
author | Sascha Wilde <wilde@intevation.de> |
---|---|
date | Thu, 26 Sep 2019 12:16:23 +0200 |
parents | 51e90370eced |
children | 6270951dda28 |
rev | line source |
---|---|
1627
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 // This is Free Software under GNU Affero General Public License v >= 3.0 |
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 // without warranty, see README.md and license for details. |
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 // |
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 // SPDX-License-Identifier: AGPL-3.0-or-later |
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 // License-Filename: LICENSES/AGPL-3.0.txt |
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 // |
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 // Copyright (C) 2018 by via donau |
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 // – Österreichische Wasserstraßen-Gesellschaft mbH |
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 // Software engineering by Intevation GmbH |
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 // |
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 // Author(s): |
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 // * Sascha L. Teichmann <sascha.teichmann@intevation.de> |
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 |
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 package imports |
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 |
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 import ( |
1653
06f08458d666
Scheduled imports: Load configuration from database when triggered by cron.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1627
diff
changeset
|
17 "context" |
06f08458d666
Scheduled imports: Load configuration from database when triggered by cron.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1627
diff
changeset
|
18 "database/sql" |
1627
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 "encoding/json" |
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 "fmt" |
2051
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
21 "sort" |
1627
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 |
1653
06f08458d666
Scheduled imports: Load configuration from database when triggered by cron.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1627
diff
changeset
|
23 "gemma.intevation.de/gemma/pkg/auth" |
1708
49e047c2106e
Imports: Made imports re-runnable if they fail.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1705
diff
changeset
|
24 "gemma.intevation.de/gemma/pkg/common" |
1627
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 ) |
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 |
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 type ( |
1696
ad5e1cddaa09
Imports: Resolved the remaining golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1653
diff
changeset
|
28 // ImportKind is a string which has to be one |
ad5e1cddaa09
Imports: Resolved the remaining golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1653
diff
changeset
|
29 // of the registered import types. |
1627
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 ImportKind string |
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 |
4178
51e90370eced
A few more doc strings to make 'golint' a little bit more happy with the imports package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4177
diff
changeset
|
32 // ImportConfigIn is used to de-serialize JSON |
51e90370eced
A few more doc strings to make 'golint' a little bit more happy with the imports package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4177
diff
changeset
|
33 // configurations coming from the REST endpoints |
51e90370eced
A few more doc strings to make 'golint' a little bit more happy with the imports package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4177
diff
changeset
|
34 // to be stored in the database. |
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
|
35 ImportConfigIn struct { |
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
|
36 Kind ImportKind `json:"kind"` |
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
|
37 Config json.RawMessage `json:"config"` |
1627
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 } |
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 |
4178
51e90370eced
A few more doc strings to make 'golint' a little bit more happy with the imports package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4177
diff
changeset
|
40 // ImportConfigOut is used to serialize |
51e90370eced
A few more doc strings to make 'golint' a little bit more happy with the imports package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4177
diff
changeset
|
41 // JSON versions to the REST endpoints |
51e90370eced
A few more doc strings to make 'golint' a little bit more happy with the imports package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4177
diff
changeset
|
42 // which are stored in the database. |
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
|
43 ImportConfigOut struct { |
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
|
44 ID int64 `json:"id"` |
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
|
45 Kind ImportKind `json:"kind"` |
2049
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
46 User string `json:"user"` |
2045
10a1e139d2e8
Imports: Re-enabled running configured imports.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2042
diff
changeset
|
47 Config interface{} `json:"config,omitempty"` |
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
|
48 } |
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
|
49 |
4178
51e90370eced
A few more doc strings to make 'golint' a little bit more happy with the imports package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4177
diff
changeset
|
50 // PersistentConfig is the the in-memory |
51e90370eced
A few more doc strings to make 'golint' a little bit more happy with the imports package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4177
diff
changeset
|
51 // representation of a configuration |
51e90370eced
A few more doc strings to make 'golint' a little bit more happy with the imports package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4177
diff
changeset
|
52 // which is stored in the database. |
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
|
53 PersistentConfig struct { |
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
|
54 ID int64 |
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
|
55 User string |
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
|
56 Kind string |
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
|
57 Attributes common.Attributes |
1627
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 } |
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 ) |
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 |
1696
ad5e1cddaa09
Imports: Resolved the remaining golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1653
diff
changeset
|
61 // UnmarshalJSON checks if the incoming string |
ad5e1cddaa09
Imports: Resolved the remaining golint issues with this package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1653
diff
changeset
|
62 // is a registered import type. |
1627
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 func (ik *ImportKind) UnmarshalJSON(data []byte) error { |
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 var s string |
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 if err := json.Unmarshal(data, &s); err != nil { |
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 return err |
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 } |
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 |
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 if !HasImportKindName(s) { |
4177
8b75ac5e243e
Made 'staticcheck' happy with pgxutils package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
3515
diff
changeset
|
70 return fmt.Errorf("unknown kind '%s'", s) |
1627
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 } |
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 |
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 *ik = ImportKind(s) |
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 |
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 return nil |
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 } |
b10aa02d7819
Refactored: Moved REST /api/imports/scheduler to /api/imports/config
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 |
1653
06f08458d666
Scheduled imports: Load configuration from database when triggered by cron.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1627
diff
changeset
|
78 const ( |
06f08458d666
Scheduled imports: Load configuration from database when triggered by cron.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1627
diff
changeset
|
79 configUser = "sys_admin" |
06f08458d666
Scheduled imports: Load configuration from database when triggered by cron.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1627
diff
changeset
|
80 |
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
|
81 loadPersistentConfigSQL = ` |
1653
06f08458d666
Scheduled imports: Load configuration from database when triggered by cron.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1627
diff
changeset
|
82 SELECT |
06f08458d666
Scheduled imports: Load configuration from database when triggered by cron.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1627
diff
changeset
|
83 username, |
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
|
84 kind |
1995
59055c8301df
Move import queue to its own database namespace
Tom Gottfried <tom@intevation.de>
parents:
1754
diff
changeset
|
85 FROM import.import_configuration |
1653
06f08458d666
Scheduled imports: Load configuration from database when triggered by cron.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1627
diff
changeset
|
86 WHERE id = $1` |
1702
49b89575ab31
Import configuration: [WIP] Added table for extra configuration attributes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1696
diff
changeset
|
87 |
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
|
88 loadPersistentConfigAttributesSQL = ` |
1702
49b89575ab31
Import configuration: [WIP] Added table for extra configuration attributes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1696
diff
changeset
|
89 SELECT k, v |
1995
59055c8301df
Move import queue to its own database namespace
Tom Gottfried <tom@intevation.de>
parents:
1754
diff
changeset
|
90 FROM import.import_configuration_attributes |
1702
49b89575ab31
Import configuration: [WIP] Added table for extra configuration attributes.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1696
diff
changeset
|
91 WHERE import_configuration_id = $1` |
2049
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
92 |
2050
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
93 hasImportConfigurationSQL = ` |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
94 SELECT true FROM import.import_configuration |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
95 WHERE id = $1` |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
96 |
2049
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
97 deleteImportConfiguationAttributesSQL = ` |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
98 DELETE FROM import.import_configuration_attributes |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
99 WHERE import_configuration_id = $1` |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
100 |
2050
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
101 deleteImportConfiguationSQL = ` |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
102 DELETE FROM import.import_configuration |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
103 WHERE id = $1` |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
104 |
2049
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
105 updateImportConfigurationSQL = ` |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
106 UPDATE import.import_configuration SET |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
107 username = $2, |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
108 kind = $3 |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
109 WHERE id = $1` |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
110 |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
111 selectImportConfigurationsByID = ` |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
112 SELECT |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
113 c.id AS id, |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
114 username, |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
115 kind, |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
116 a.k, |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
117 a.v |
2090
4882f01c8592
Imports config: Fixed listing of stored configurations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2060
diff
changeset
|
118 FROM import.import_configuration c LEFT JOIN |
2049
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
119 import.import_configuration_attributes a |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
120 ON c.id = a.import_configuration_id |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
121 ORDER by c.id` |
2051
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
122 |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
123 insertImportConfigurationSQL = ` |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
124 INSERT INTO import.import_configuration |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
125 (username, kind) |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
126 VALUES ($1, $2) |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
127 RETURNING id` |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
128 |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
129 insertImportConfigurationAttributeSQL = ` |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
130 INSERT INTO import.import_configuration_attributes |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
131 (import_configuration_id, k, v) |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
132 VALUES ($1, $2, $3)` |
1653
06f08458d666
Scheduled imports: Load configuration from database when triggered by cron.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1627
diff
changeset
|
133 ) |
06f08458d666
Scheduled imports: Load configuration from database when triggered by cron.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1627
diff
changeset
|
134 |
4178
51e90370eced
A few more doc strings to make 'golint' a little bit more happy with the imports package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4177
diff
changeset
|
135 // UpdateContext stores an updated configuration to the database. |
2052
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
136 func (pc *PersistentConfig) UpdateContext(ctx context.Context, tx *sql.Tx) error { |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
137 if _, err := tx.ExecContext( |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
138 ctx, |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
139 updateImportConfigurationSQL, |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
140 pc.ID, pc.User, pc.Kind, |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
141 ); err != nil { |
2049
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
142 return err |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
143 } |
2052
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
144 if _, err := tx.ExecContext( |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
145 ctx, |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
146 deleteImportConfiguationAttributesSQL, |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
147 pc.ID, |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
148 ); err != nil { |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
149 return err |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
150 } |
0b203a3b3e8e
Imports: Re-enabled /imports/config/{id} PATCH.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2051
diff
changeset
|
151 return storeConfigAttributes(ctx, tx, pc.ID, pc.Attributes) |
2049
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
152 } |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
153 |
4178
51e90370eced
A few more doc strings to make 'golint' a little bit more happy with the imports package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4177
diff
changeset
|
154 // LoadPersistentConfigContext loads a configuration from the database. |
2050
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
155 func LoadPersistentConfigContext( |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
156 ctx context.Context, |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
157 conn *sql.Conn, |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
158 id int64, |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
159 ) (*PersistentConfig, error) { |
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
|
160 |
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
|
161 cfg := &PersistentConfig{ID: id} |
1653
06f08458d666
Scheduled imports: Load configuration from database when triggered by cron.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1627
diff
changeset
|
162 |
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
|
163 err := conn.QueryRowContext(ctx, loadPersistentConfigSQL, id).Scan( |
1739
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1708
diff
changeset
|
164 &cfg.User, |
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
|
165 &cfg.Kind, |
1739
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1708
diff
changeset
|
166 ) |
1653
06f08458d666
Scheduled imports: Load configuration from database when triggered by cron.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1627
diff
changeset
|
167 |
06f08458d666
Scheduled imports: Load configuration from database when triggered by cron.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1627
diff
changeset
|
168 switch { |
06f08458d666
Scheduled imports: Load configuration from database when triggered by cron.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1627
diff
changeset
|
169 case err == sql.ErrNoRows: |
06f08458d666
Scheduled imports: Load configuration from database when triggered by cron.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1627
diff
changeset
|
170 return nil, nil |
06f08458d666
Scheduled imports: Load configuration from database when triggered by cron.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1627
diff
changeset
|
171 case err != nil: |
06f08458d666
Scheduled imports: Load configuration from database when triggered by cron.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1627
diff
changeset
|
172 return nil, err |
06f08458d666
Scheduled imports: Load configuration from database when triggered by cron.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1627
diff
changeset
|
173 } |
06f08458d666
Scheduled imports: Load configuration from database when triggered by cron.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1627
diff
changeset
|
174 |
1739
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1708
diff
changeset
|
175 // load the extra attributes. |
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
|
176 rows, err := conn.QueryContext(ctx, loadPersistentConfigAttributesSQL, id) |
1739
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1708
diff
changeset
|
177 if err != nil { |
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1708
diff
changeset
|
178 return nil, err |
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1708
diff
changeset
|
179 } |
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1708
diff
changeset
|
180 defer rows.Close() |
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1708
diff
changeset
|
181 var attributes common.Attributes |
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1708
diff
changeset
|
182 for rows.Next() { |
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1708
diff
changeset
|
183 var k, v string |
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1708
diff
changeset
|
184 if err = rows.Scan(&k, &v); err != nil { |
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1708
diff
changeset
|
185 return nil, err |
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1708
diff
changeset
|
186 } |
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1708
diff
changeset
|
187 if attributes == nil { |
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1708
diff
changeset
|
188 attributes = common.Attributes{} |
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1708
diff
changeset
|
189 } |
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1708
diff
changeset
|
190 attributes[k] = v |
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1708
diff
changeset
|
191 } |
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1708
diff
changeset
|
192 if err = rows.Err(); err != nil { |
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1708
diff
changeset
|
193 return nil, err |
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1708
diff
changeset
|
194 } |
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1708
diff
changeset
|
195 if len(attributes) > 0 { |
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1708
diff
changeset
|
196 cfg.Attributes = attributes |
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1708
diff
changeset
|
197 } |
1653
06f08458d666
Scheduled imports: Load configuration from database when triggered by cron.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1627
diff
changeset
|
198 return cfg, nil |
06f08458d666
Scheduled imports: Load configuration from database when triggered by cron.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1627
diff
changeset
|
199 } |
1739
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1708
diff
changeset
|
200 |
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
|
201 func loadPersistentConfig(id int64) (*PersistentConfig, error) { |
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
|
202 return loadPersistentConfigContext(context.Background(), id) |
1739
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1708
diff
changeset
|
203 } |
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1708
diff
changeset
|
204 |
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
|
205 func loadPersistentConfigContext(ctx context.Context, id int64) (*PersistentConfig, error) { |
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
|
206 var cfg *PersistentConfig |
1739
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1708
diff
changeset
|
207 err := auth.RunAs(ctx, configUser, func(conn *sql.Conn) error { |
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1708
diff
changeset
|
208 var err error |
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
|
209 cfg, err = LoadPersistentConfigContext(ctx, conn, id) |
1739
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1708
diff
changeset
|
210 return err |
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1708
diff
changeset
|
211 }) |
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1708
diff
changeset
|
212 return cfg, err |
61fa62f01f20
Configured imports: When GET an import deliver the extra attributes, too.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
1708
diff
changeset
|
213 } |
2049
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
214 |
4178
51e90370eced
A few more doc strings to make 'golint' a little bit more happy with the imports package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4177
diff
changeset
|
215 // ListAllPersistentConfigurationsContext iterates over all |
51e90370eced
A few more doc strings to make 'golint' a little bit more happy with the imports package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4177
diff
changeset
|
216 // configurations stored in the database and reports every |
51e90370eced
A few more doc strings to make 'golint' a little bit more happy with the imports package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4177
diff
changeset
|
217 // particular one to the callback fn. |
2049
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
218 func ListAllPersistentConfigurationsContext( |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
219 ctx context.Context, |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
220 conn *sql.Conn, |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
221 fn func(*ImportConfigOut) error, |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
222 ) error { |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
223 |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
224 rows, err := conn.QueryContext(ctx, selectImportConfigurationsByID) |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
225 if err != nil { |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
226 return err |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
227 } |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
228 defer rows.Close() |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
229 |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
230 var ( |
2090
4882f01c8592
Imports config: Fixed listing of stored configurations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2060
diff
changeset
|
231 first = true |
4882f01c8592
Imports config: Fixed listing of stored configurations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2060
diff
changeset
|
232 pc PersistentConfig |
2049
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
233 ) |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
234 |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
235 send := func() error { |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
236 kind := JobKind(pc.Kind) |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
237 ctor := ImportModelForJobKind(kind) |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
238 if ctor == nil { |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
239 return fmt.Errorf("unable to deserialize kind '%s'", pc.Kind) |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
240 } |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
241 config := ctor() |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
242 pc.Attributes.Unmarshal(config) |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
243 return fn(&ImportConfigOut{ |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
244 ID: pc.ID, |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
245 Kind: ImportKind(pc.Kind), |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
246 User: pc.User, |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
247 Config: config, |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
248 }) |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
249 } |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
250 |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
251 for rows.Next() { |
2090
4882f01c8592
Imports config: Fixed listing of stored configurations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2060
diff
changeset
|
252 var ( |
4882f01c8592
Imports config: Fixed listing of stored configurations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2060
diff
changeset
|
253 id int64 |
4882f01c8592
Imports config: Fixed listing of stored configurations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2060
diff
changeset
|
254 user, kind string |
4882f01c8592
Imports config: Fixed listing of stored configurations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2060
diff
changeset
|
255 k, v sql.NullString |
4882f01c8592
Imports config: Fixed listing of stored configurations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2060
diff
changeset
|
256 ) |
2060
f9d13ce57893
Imports: Fixed SQL scanning in listing all configurations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2052
diff
changeset
|
257 if err := rows.Scan( |
2090
4882f01c8592
Imports config: Fixed listing of stored configurations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2060
diff
changeset
|
258 &id, |
4882f01c8592
Imports config: Fixed listing of stored configurations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2060
diff
changeset
|
259 &user, |
4882f01c8592
Imports config: Fixed listing of stored configurations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2060
diff
changeset
|
260 &kind, |
2060
f9d13ce57893
Imports: Fixed SQL scanning in listing all configurations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2052
diff
changeset
|
261 &k, &v, |
f9d13ce57893
Imports: Fixed SQL scanning in listing all configurations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2052
diff
changeset
|
262 ); err != nil { |
2049
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
263 return err |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
264 } |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
265 if !first { |
2090
4882f01c8592
Imports config: Fixed listing of stored configurations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2060
diff
changeset
|
266 if pc.ID != id { |
2049
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
267 if err := send(); err != nil { |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
268 return err |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
269 } |
2090
4882f01c8592
Imports config: Fixed listing of stored configurations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2060
diff
changeset
|
270 pc.ID = id |
4882f01c8592
Imports config: Fixed listing of stored configurations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2060
diff
changeset
|
271 pc.User = user |
4882f01c8592
Imports config: Fixed listing of stored configurations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2060
diff
changeset
|
272 pc.Kind = kind |
2049
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
273 pc.Attributes = nil |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
274 } |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
275 } else { |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
276 first = false |
2090
4882f01c8592
Imports config: Fixed listing of stored configurations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2060
diff
changeset
|
277 pc.ID = id |
4882f01c8592
Imports config: Fixed listing of stored configurations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2060
diff
changeset
|
278 pc.User = user |
4882f01c8592
Imports config: Fixed listing of stored configurations.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2060
diff
changeset
|
279 pc.Kind = kind |
2049
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
280 } |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
281 |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
282 if k.Valid && v.Valid { |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
283 if pc.Attributes == nil { |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
284 pc.Attributes = common.Attributes{} |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
285 } |
3515
c64c47ff2ab1
import: fix for passwordleakage. No passwords are received/sent if configuration is edited.
Thomas Junk <thomas.junk@intevation.de>
parents:
2090
diff
changeset
|
286 // Prevent sending the `password` back to the client. |
c64c47ff2ab1
import: fix for passwordleakage. No passwords are received/sent if configuration is edited.
Thomas Junk <thomas.junk@intevation.de>
parents:
2090
diff
changeset
|
287 // (See importconfig.infoImportConfig() for the other place |
c64c47ff2ab1
import: fix for passwordleakage. No passwords are received/sent if configuration is edited.
Thomas Junk <thomas.junk@intevation.de>
parents:
2090
diff
changeset
|
288 // 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:
2090
diff
changeset
|
289 if k.String != "password" { |
c64c47ff2ab1
import: fix for passwordleakage. No passwords are received/sent if configuration is edited.
Thomas Junk <thomas.junk@intevation.de>
parents:
2090
diff
changeset
|
290 pc.Attributes.Set(k.String, v.String) |
c64c47ff2ab1
import: fix for passwordleakage. No passwords are received/sent if configuration is edited.
Thomas Junk <thomas.junk@intevation.de>
parents:
2090
diff
changeset
|
291 } |
2049
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
292 } |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
293 } |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
294 |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
295 if err := rows.Err(); err != nil { |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
296 return err |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
297 } |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
298 |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
299 err = nil |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
300 if !first { |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
301 err = send() |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
302 } |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
303 return err |
d1a680be7ae4
Imports. Re-enabled /imports/config GET.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2045
diff
changeset
|
304 } |
2050
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
305 |
4178
51e90370eced
A few more doc strings to make 'golint' a little bit more happy with the imports package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4177
diff
changeset
|
306 // DeletePersistentConfigurationContext deletes |
51e90370eced
A few more doc strings to make 'golint' a little bit more happy with the imports package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4177
diff
changeset
|
307 // a configuration from the database identified by |
51e90370eced
A few more doc strings to make 'golint' a little bit more happy with the imports package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4177
diff
changeset
|
308 // its id. |
2050
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
309 func DeletePersistentConfigurationContext( |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
310 ctx context.Context, |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
311 tx *sql.Tx, |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
312 id int64, |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
313 ) error { |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
314 var found bool |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
315 if err := tx.QueryRowContext( |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
316 ctx, |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
317 hasImportConfigurationSQL, |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
318 id, |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
319 ).Scan(&found); err != nil { |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
320 return err |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
321 } |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
322 if !found { |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
323 return sql.ErrNoRows |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
324 } |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
325 if _, err := tx.ExecContext( |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
326 ctx, |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
327 deleteImportConfiguationAttributesSQL, |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
328 id, |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
329 ); err != nil { |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
330 return nil |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
331 } |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
332 _, err := tx.ExecContext( |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
333 ctx, |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
334 deleteImportConfiguationSQL, |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
335 id, |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
336 ) |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
337 return err |
a3ccef8ec304
Imports: Re-enabled /imports/config/{id} DELETE.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2049
diff
changeset
|
338 } |
2051
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
339 |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
340 func storeConfigAttributes( |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
341 ctx context.Context, |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
342 tx *sql.Tx, |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
343 id int64, |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
344 attrs common.Attributes, |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
345 ) error { |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
346 if len(attrs) == 0 { |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
347 return nil |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
348 } |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
349 attrStmt, err := tx.PrepareContext(ctx, insertImportConfigurationAttributeSQL) |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
350 if err != nil { |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
351 return err |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
352 } |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
353 defer attrStmt.Close() |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
354 // Sort to make it deterministic |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
355 keys := make([]string, len(attrs)) |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
356 i := 0 |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
357 for key := range attrs { |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
358 keys[i] = key |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
359 i++ |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
360 } |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
361 sort.Strings(keys) |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
362 for _, key := range keys { |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
363 if _, err := attrStmt.ExecContext(ctx, id, key, attrs[key]); err != nil { |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
364 return err |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
365 } |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
366 } |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
367 return nil |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
368 } |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
369 |
4178
51e90370eced
A few more doc strings to make 'golint' a little bit more happy with the imports package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4177
diff
changeset
|
370 // StoreContext stores a configuration to the database and returns |
51e90370eced
A few more doc strings to make 'golint' a little bit more happy with the imports package.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
4177
diff
changeset
|
371 // its new database id. |
2051
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
372 func (pc *PersistentConfig) StoreContext(ctx context.Context, tx *sql.Tx) (int64, error) { |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
373 var id int64 |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
374 if err := tx.QueryRowContext( |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
375 ctx, |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
376 insertImportConfigurationSQL, |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
377 pc.User, |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
378 pc.Kind, |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
379 ).Scan(&id); err != nil { |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
380 return 0, err |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
381 } |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
382 |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
383 if err := storeConfigAttributes(ctx, tx, id, pc.Attributes); err != nil { |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
384 return 0, err |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
385 } |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
386 pc.ID = id |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
387 return id, nil |
7d627258e045
Imports: Re-enabled /imports/config POST.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2050
diff
changeset
|
388 } |