Skip to content

Commit 7463695

Browse files
Merge branch 'master' into fix/pipeline-github-token
2 parents 4187871 + dd0daf9 commit 7463695

File tree

93 files changed

+3915
-1612
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+3915
-1612
lines changed

.github/workflows/draft-release.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ on:
1010
jobs:
1111
update_release_draft:
1212
runs-on: ubuntu-latest
13+
permissions:
14+
contents: write
15+
pull-requests: write
1316
steps:
1417
- uses: release-drafter/release-drafter@v5
1518
env:

.github/workflows/pull_request.yaml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ jobs:
1313
- name: Generate Docs
1414
run: |
1515
export PATH=$PATH:/home/runner/go/bin
16-
make docs-prepare
17-
tfplugindocs generate
16+
make docs
1817
- name: Validate No Changes
1918
run: |
2019
git diff --exit-code

GNUmakefile

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,9 @@ PKG_NAME=codefresh
66
NAMESPACE=app
77
BINARY=terraform-provider-${PKG_NAME}
88
OS_ARCH=darwin_amd64
9-
TFPLUGINDOCS_VERSION=v0.14.1
109

1110
default: build
1211

13-
tools:
14-
GO111MODULE=on go install github.com/client9/misspell/cmd/misspell
15-
GO111MODULE=on go install github.com/golangci/golangci-lint/cmd/golangci-lint
16-
GO111MODULE=on go install github.com/bflad/tfproviderlint/cmd/tfproviderlint
17-
1812
build: fmtcheck
1913
go install
2014
go build -o ${BINARY}
@@ -31,7 +25,7 @@ fmtcheck:
3125

3226
lint:
3327
@echo "==> Checking source code against linters..."
34-
golangci-lint run ./...
28+
go tool golangci-lint run ./...
3529

3630
test: fmtcheck
3731
go test -i $(TEST) || exit 1
@@ -58,13 +52,8 @@ vet:
5852
exit 1; \
5953
fi
6054

61-
docs-prepare:
62-
@echo "==> Setting up tfplugindocs..."
63-
go install github.com/hashicorp/terraform-plugin-docs/cmd/tfplugindocs@${TFPLUGINDOCS_VERSION}
64-
65-
docs: docs-prepare
55+
docs:
6656
@echo "==> Generating Provider Documentation..."
67-
tfplugindocs generate
68-
69-
.PHONY: build test testacc vet fmt fmtcheck lint tools test-compile docs docs-prepare
57+
go tool tfplugindocs generate
7058

59+
.PHONY: build test testacc vet fmt fmtcheck lint test-compile docs docs-prepare

codefresh.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ steps:
1515
go_fmt:
1616
title: "Formatting"
1717
stage: test
18-
image: goreleaser/goreleaser:v1.17.0
18+
image: golang:1.24.3-alpine3.21
1919
commands:
2020
- go fmt
2121

2222
go_test:
2323
title: "Run tests"
2424
stage: test
25-
image: golang:1.18.10-alpine3.17
25+
image: golang:1.24.3-alpine3.21
2626
environment:
2727
- TF_ACC="test"
2828
- CGO_ENABLED=0
@@ -39,7 +39,7 @@ steps:
3939
# The following will resolve to their latest patch version
4040
environment:
4141
- TF_VERSION=1.3.0
42-
- TF_VERSION=1.7.0
42+
- TF_VERSION=1.11.4
4343
when:
4444
condition:
4545
all:

codefresh/cfclient/account.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import (
44
"errors"
55
"fmt"
66

7-
"github.com/imdario/mergo"
7+
"dario.cat/mergo"
88
)
99

1010
type DockerRegistry struct {

codefresh/cfclient/api_key.go

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,95 @@ func (client *Client) GetApiKeysList() ([]ApiKey, error) {
245245
return apiKeys, nil
246246
}
247247

248+
func (client *Client) GetAPIKeyServiceUser(keyID string, serviceUserId string) (*ApiKey, error) {
249+
250+
opts := RequestOptions{
251+
Path: fmt.Sprintf("/auth/key/service-user/%s/%s", serviceUserId, keyID),
252+
Method: "GET",
253+
}
254+
255+
resp, err := client.RequestAPI(&opts)
256+
257+
if err != nil {
258+
return nil, err
259+
}
260+
261+
var apiKey ApiKey
262+
263+
err = DecodeResponseInto(resp, &apiKey)
264+
if err != nil {
265+
return nil, err
266+
}
267+
268+
return &apiKey, nil
269+
}
270+
271+
func (client *Client) DeleteAPIKeyServiceUser(keyID string, serviceUserId string) error {
272+
273+
opts := RequestOptions{
274+
Path: fmt.Sprintf("/auth/key/service-user/%s/%s", serviceUserId, keyID),
275+
Method: "DELETE",
276+
}
277+
278+
resp, err := client.RequestAPI(&opts)
279+
if err != nil {
280+
fmt.Println(string(resp))
281+
return err
282+
}
283+
284+
return nil
285+
}
286+
287+
func (client *Client) UpdateAPIKeyServiceUser(key *ApiKey, serviceUserId string) error {
288+
289+
keyID := key.ID
290+
if keyID == "" {
291+
return errors.New("[ERROR] Key ID is empty")
292+
}
293+
294+
body, err := EncodeToJSON(key)
295+
if err != nil {
296+
return err
297+
}
298+
299+
opts := RequestOptions{
300+
Path: fmt.Sprintf("/auth/key/service-user/%s/%s", serviceUserId, keyID),
301+
Method: "PATCH",
302+
Body: body,
303+
}
304+
305+
resp, err := client.RequestAPI(&opts)
306+
307+
if err != nil {
308+
fmt.Println(string(resp))
309+
return err
310+
}
311+
312+
return nil
313+
}
314+
315+
func (client *Client) CreateApiKeyServiceUser(serviceUserId string, apiKey *ApiKey) (string, error) {
316+
317+
body, err := EncodeToJSON(apiKey)
318+
if err != nil {
319+
return "", err
320+
}
321+
322+
opts := RequestOptions{
323+
Path: fmt.Sprintf("/auth/key/service-user/%s", serviceUserId),
324+
Method: "POST",
325+
Body: body,
326+
}
327+
328+
resp, err := client.RequestAPI(&opts)
329+
330+
if err != nil {
331+
return "", err
332+
}
333+
334+
return string(resp), nil
335+
}
336+
248337
func (client *Client) createRandomUser(accountId string) (string, error) {
249338
// add user
250339
userPrefix := acctest.RandString(10)

codefresh/cfclient/client.go

Lines changed: 34 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,19 @@ import (
44
"bytes"
55
"encoding/json"
66
"fmt"
7-
"io/ioutil"
7+
"io"
88
"net/http"
99
"strings"
1010
)
1111

1212
// Client token, host, htpp.Client
1313
type Client struct {
14-
Token string
15-
TokenHeader string
16-
Host string
17-
HostV2 string
18-
Client *http.Client
14+
Token string
15+
TokenHeader string
16+
Host string
17+
HostV2 string
18+
featureFlags map[string]bool
19+
Client *http.Client
1920
}
2021

2122
// RequestOptions path, method, etc
@@ -35,11 +36,12 @@ func NewClient(hostname string, hostnameV2 string, token string, tokenHeader str
3536
tokenHeader = "Authorization"
3637
}
3738
return &Client{
38-
Host: hostname,
39-
HostV2: hostnameV2,
40-
Token: token,
41-
TokenHeader: tokenHeader,
42-
Client: &http.Client{},
39+
Host: hostname,
40+
HostV2: hostnameV2,
41+
Token: token,
42+
TokenHeader: tokenHeader,
43+
Client: &http.Client{},
44+
featureFlags: map[string]bool{},
4345
}
4446

4547
}
@@ -69,7 +71,7 @@ func (client *Client) RequestAPI(opt *RequestOptions) ([]byte, error) {
6971
}
7072
defer resp.Body.Close()
7173

72-
body, err := ioutil.ReadAll(resp.Body)
74+
body, err := io.ReadAll(resp.Body)
7375
if err != nil {
7476
return nil, fmt.Errorf("Failed to read body %v %v", resp.StatusCode, resp.Status)
7577
}
@@ -101,7 +103,7 @@ func (client *Client) RequestApiXAccessToken(opt *RequestOptions) ([]byte, error
101103
}
102104
defer resp.Body.Close()
103105

104-
body, err := ioutil.ReadAll(resp.Body)
106+
body, err := io.ReadAll(resp.Body)
105107
if err != nil {
106108
return nil, fmt.Errorf("Failed to read body %v %v", resp.StatusCode, resp.Status)
107109
}
@@ -112,6 +114,25 @@ func (client *Client) RequestApiXAccessToken(opt *RequestOptions) ([]byte, error
112114
return body, nil
113115
}
114116

117+
func (client *Client) isFeatureFlagEnabled(flagName string) (bool, error) {
118+
119+
if len(client.featureFlags) == 0 {
120+
currAcc, err := client.GetCurrentAccount()
121+
122+
if err != nil {
123+
return false, err
124+
}
125+
126+
client.featureFlags = currAcc.FeatureFlags
127+
}
128+
129+
if val, ok := client.featureFlags[flagName]; ok {
130+
return val, nil
131+
}
132+
133+
return false, nil
134+
}
135+
115136
// ToQS add extra parameters to path
116137
func ToQS(qs map[string]string) string {
117138
var arr = []string{}

codefresh/cfclient/context.go

Lines changed: 34 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,16 @@ import (
44
"fmt"
55
"log"
66
"net/url"
7+
"slices"
78
)
89

10+
var encryptedContextTypes = []string{
11+
"secret",
12+
"secret-yaml",
13+
"storage.s3",
14+
"storage.azuref",
15+
}
16+
917
type ContextErrorResponse struct {
1018
Status int `json:"status,omitempty"`
1119
Message string `json:"message,omitempty"`
@@ -17,9 +25,10 @@ type ContextMetadata struct {
1725
}
1826

1927
type Context struct {
20-
Metadata ContextMetadata `json:"metadata,omitempty"`
21-
Spec ContextSpec `json:"spec,omitempty"`
22-
Version string `json:"version,omitempty"`
28+
Metadata ContextMetadata `json:"metadata,omitempty"`
29+
Spec ContextSpec `json:"spec,omitempty"`
30+
Version string `json:"version,omitempty"`
31+
IsEncrypred bool `json:"isEncrypted,omitempty"`
2332
}
2433

2534
type ContextSpec struct {
@@ -32,7 +41,18 @@ func (context *Context) GetID() string {
3241
}
3342

3443
func (client *Client) GetContext(name string) (*Context, error) {
35-
fullPath := fmt.Sprintf("/contexts/%s?decrypt=true", url.PathEscape(name))
44+
fullPath := fmt.Sprintf("/contexts/%s", url.PathEscape(name))
45+
46+
forbidDecrypt, err := client.isFeatureFlagEnabled("forbidDecrypt")
47+
48+
if err != nil {
49+
forbidDecrypt = false
50+
}
51+
52+
if !forbidDecrypt {
53+
fullPath += "?decrypt=true"
54+
}
55+
3656
opts := RequestOptions{
3757
Path: fullPath,
3858
Method: "GET",
@@ -49,8 +69,17 @@ func (client *Client) GetContext(name string) (*Context, error) {
4969
return nil, err
5070
}
5171

52-
return &respContext, nil
72+
// This is so not to break existing behavior while adding support for forbidDecrypt feature flag
73+
// The provider used to always decrypt the contexts, hence we treat all contexts as decrypted unless forbidDecrypt is set
74+
isEncryptedType := slices.Contains(encryptedContextTypes, respContext.Spec.Type)
75+
76+
respContext.IsEncrypred = false
5377

78+
if forbidDecrypt && isEncryptedType {
79+
respContext.IsEncrypred = true
80+
}
81+
82+
return &respContext, nil
5483
}
5584

5685
func (client *Client) CreateContext(context *Context) (*Context, error) {

0 commit comments

Comments
 (0)