Skip to content

Commit 14205f9

Browse files
author
Oleg Sucharevich
committed
implement codefresh API to validate and sign runtime environment
1 parent 1c71b73 commit 14205f9

File tree

1 file changed

+42
-3
lines changed

1 file changed

+42
-3
lines changed

pkg/codefresh/runtime_enrionment.go

Lines changed: 42 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ type (
66
// IRuntimeEnvironmentAPI declers Codefresh runtime environment API
77
IRuntimeEnvironmentAPI interface {
88
CreateRuntimeEnvironment(*CreateRuntimeOptions) (*RuntimeEnvironment, error)
9+
ValidateRuntimeEnvironment(*ValidateRuntimeOptions) error
10+
SignRuntimeEnvironmentCertificate(*SignCertificatesOptions) ([]byte, error)
911
}
1012

1113
RuntimeEnvironment struct {
@@ -18,14 +20,23 @@ type (
1820
HasAgent bool
1921
}
2022

23+
ValidateRuntimeOptions struct {
24+
Cluster string
25+
Namespace string
26+
}
27+
28+
SignCertificatesOptions struct {
29+
AltName string
30+
CSR string
31+
}
32+
2133
createRuntimeEnvironmentResponse struct {
2234
Name string
2335
}
2436
)
2537

2638
// CreateRuntimeEnvironment - create Runtime-Environment
2739
func (c *codefresh) CreateRuntimeEnvironment(opt *CreateRuntimeOptions) (*RuntimeEnvironment, error) {
28-
// r := &createRuntimeEnvironmentResponse{}
2940
re := &RuntimeEnvironment{
3041
Name: fmt.Sprintf("%s/%s", opt.Cluster, opt.Namespace),
3142
}
@@ -48,7 +59,35 @@ func (c *codefresh) CreateRuntimeEnvironment(opt *CreateRuntimeOptions) (*Runtim
4859

4960
if resp.StatusCode < 400 {
5061
return re, nil
51-
} else {
52-
return nil, fmt.Errorf("Error during runtime environment creation")
5362
}
63+
return nil, fmt.Errorf("Error during runtime environment creation")
64+
}
65+
66+
func (c *codefresh) ValidateRuntimeEnvironment(opt *ValidateRuntimeOptions) error {
67+
body := map[string]interface{}{
68+
"clusterName": opt.Cluster,
69+
"namespace": opt.Namespace,
70+
}
71+
_, err := c.requestAPI(&requestOptions{
72+
path: "/api/custom_clusters/validate",
73+
method: "POST",
74+
body: body,
75+
})
76+
return err
77+
}
78+
79+
func (c *codefresh) SignRuntimeEnvironmentCertificate(opt *SignCertificatesOptions) ([]byte, error) {
80+
body := map[string]interface{}{
81+
"reqSubjectAltName": opt.AltName,
82+
"csr": opt.CSR,
83+
}
84+
resp, err := c.requestAPI(&requestOptions{
85+
path: "/api/custom_clusters/signServerCerts",
86+
method: "POST",
87+
body: body,
88+
})
89+
if err != nil {
90+
return nil, err
91+
}
92+
return resp.Bytes(), nil
5493
}

0 commit comments

Comments
 (0)