Skip to content

Commit 38499ae

Browse files
committed
feature-flags
1 parent 44f6743 commit 38499ae

File tree

2 files changed

+55
-15
lines changed

2 files changed

+55
-15
lines changed

client/account.go

+12-15
Original file line numberDiff line numberDiff line change
@@ -249,17 +249,17 @@ func (client *Client) UpdateAccount(account *Account) (*Account, error) {
249249
return nil, errors.New("[ERROR] Account ID is empty")
250250
}
251251

252-
existingAccount, err := client.GetAccountByID(id)
252+
accountToUpdate, err := client.GetAccountByID(id)
253253
if err != nil {
254254
return nil, err
255255
}
256256

257-
err = mergo.Merge(account, existingAccount)
257+
err = mergo.MergeWithOverwrite(accountToUpdate, account)
258258
if err != nil {
259259
return nil, err
260260
}
261261

262-
putAccount := AccountDetails{*account}
262+
putAccount := AccountDetails{*accountToUpdate}
263263

264264
body, err := EncodeToJSON(putAccount)
265265
if err != nil {
@@ -285,20 +285,17 @@ func (client *Client) UpdateAccount(account *Account) (*Account, error) {
285285
}
286286

287287
// Update Features
288-
var featureUpdatePath string
289-
for k, v := range account.Features{
290-
//body
288+
requestOptions := &RequestOptions{}
289+
for k, v := range account.Features{
290+
requestOptions.Body = []byte(fmt.Sprintf("{\"feature\": \"%s\"}", k))
291291
if v {
292-
featureUpdatePath = fmt.Sprintf("/features/%s", id)
292+
requestOptions.Path = fmt.Sprintf("/features/%s", id)
293+
requestOptions.Method = "POST"
293294
} else {
294-
featureUpdatePath = fmt.Sprintf("/features/switchOff/%s", id)
295-
}
296-
bodyFeatures := []byte(fmt.Sprintf("{\"feature\": \"%s\"}", k))
297-
_, err = client.RequestAPI(&RequestOptions{
298-
Path: featureUpdatePath,
299-
Method: "POST",
300-
Body: bodyFeatures,
301-
})
295+
requestOptions.Path = fmt.Sprintf("/features/switchOff/%s", id)
296+
requestOptions.Method = "PUT"
297+
}
298+
_, err = client.RequestAPI(requestOptions)
302299
if err != nil {
303300
return nil, err
304301
}

docs/developer.md

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
## Developer guide
2+
3+
We are using [Terraform Plugin SDK v2](https://github.com/hashicorp/terraform-plugin-sdk/tree/v2.0.0-rc.2)
4+
5+
### Run with Delve Debugger
6+
[Reference guide](https://www.terraform.io/docs/extend/guides/v2-upgrade-guide.html#support-for-debuggable-provider-binaries)
7+
[sdk code](https://github.com/hashicorp/terraform-plugin-sdk/blob/v2.0.0-rc.2/plugin/debug.go#L97)
8+
9+
run pluging with set env CODEFRESH_PLUGIN_DEBUG=true in delve
10+
- for vscode set launch.json like this:
11+
```json
12+
{
13+
// Use IntelliSense to learn about possible attributes.
14+
// Hover to view descriptions of existing attributes.
15+
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
16+
"version": "0.2.0",
17+
"configurations": [
18+
{
19+
"name": "terraform-provider-codefresh",
20+
"type": "go",
21+
"request": "launch",
22+
"mode": "debug",
23+
"port": 2345,
24+
"host": "127.0.0.1",
25+
"env": {"CODEFRESH_PLUGIN_DEBUG": "true"},
26+
"program": "/d1/home/kosta/devel/go/src/github.com/codefresh-io/terraform-provider-codefresh/main.go",
27+
"showLog": true,
28+
"trace": "verbose"
29+
}
30+
]
31+
}
32+
```
33+
- copy value of TF_REATTACH_PROVIDERS from the output of debug console and set it for terraform exec:
34+
```
35+
export TF_REATTACH_PROVIDERS='{"registry.terraform.io/-/codefresh":{"Protocol":"grpc","Pid":614875,"Test":true,"Addr":{"Network":"unix","String":"/tmp/plugin369955425"}}}'
36+
37+
terraform apply
38+
```
39+
40+
41+
42+
43+

0 commit comments

Comments
 (0)