@@ -5,9 +5,12 @@ import (
5
5
"encoding/json"
6
6
"fmt"
7
7
"net/url"
8
+ "strings"
9
+ "text/template"
8
10
9
11
"github.com/ovh/configstore"
10
12
"github.com/ovh/go-ovh/ovh"
13
+
11
14
"github.com/ovh/utask/pkg/plugins/builtin/httputil"
12
15
"github.com/ovh/utask/pkg/plugins/taskplugin"
13
16
"github.com/ovh/utask/pkg/utils"
@@ -34,7 +37,7 @@ type APIOVHConfig struct {
34
37
Body string `json:"body,omitempty"`
35
38
}
36
39
37
- // ovhConfig holds the the credentials needed to instantiate
40
+ // ovhConfig holds the credentials needed to instantiate
38
41
// an OVH API client
39
42
type ovhConfig struct {
40
43
Endpoint string `json:"endpoint"`
@@ -51,25 +54,30 @@ func validConfig(config interface{}) error {
51
54
default :
52
55
return fmt .Errorf ("unknown method for gw runner: %q" , cfg .Method )
53
56
}
57
+ // If the API credentials is a template, try to parse it.
58
+ if strings .Index (cfg .Credentials , "{{" ) == - 1 {
59
+ ovhCfgStr , err := configstore .GetItemValue (cfg .Credentials )
60
+ if err != nil {
61
+ return fmt .Errorf ("can't retrieve credentials from configstore: %s" , err )
62
+ }
54
63
55
- ovhCfgStr , err := configstore .GetItemValue (cfg .Credentials )
56
- if err != nil {
57
- return fmt .Errorf ("can't retrieve credentials from configstore: %s" , err )
58
- }
59
-
60
- var ovhcfg ovhConfig
61
- if err := json .Unmarshal ([]byte (ovhCfgStr ), & ovhcfg ); err != nil {
62
- return fmt .Errorf ("can't unmarshal ovhConfig from configstore: %s" , err )
63
- }
64
+ var ovhcfg ovhConfig
65
+ if err := json .Unmarshal ([]byte (ovhCfgStr ), & ovhcfg ); err != nil {
66
+ return fmt .Errorf ("can't unmarshal ovhConfig from configstore: %s" , err )
67
+ }
64
68
65
- if _ , err := ovh .NewClient (
66
- ovhcfg .Endpoint ,
67
- ovhcfg .AppKey ,
68
- ovhcfg .AppSecret ,
69
- ovhcfg .ConsumerKey ); err != nil {
70
- return fmt .Errorf ("can't create new OVH client: %s" , err )
69
+ if _ , err := ovh .NewClient (
70
+ ovhcfg .Endpoint ,
71
+ ovhcfg .AppKey ,
72
+ ovhcfg .AppSecret ,
73
+ ovhcfg .ConsumerKey ); err != nil {
74
+ return fmt .Errorf ("can't create new OVH client: %s" , err )
75
+ }
76
+ } else {
77
+ if _ , err := template .New ("credentials" ).Parse (cfg .Credentials ); err != nil {
78
+ return fmt .Errorf ("failed to parse credentials template: %w" , err )
79
+ }
71
80
}
72
-
73
81
return nil
74
82
}
75
83
0 commit comments