6
6
// IRuntimeEnvironmentAPI declers Codefresh runtime environment API
7
7
IRuntimeEnvironmentAPI interface {
8
8
CreateRuntimeEnvironment (* CreateRuntimeOptions ) (* RuntimeEnvironment , error )
9
+ ValidateRuntimeEnvironment (* ValidateRuntimeOptions ) error
10
+ SignRuntimeEnvironmentCertificate (* SignCertificatesOptions ) ([]byte , error )
9
11
}
10
12
11
13
RuntimeEnvironment struct {
@@ -18,14 +20,23 @@ type (
18
20
HasAgent bool
19
21
}
20
22
23
+ ValidateRuntimeOptions struct {
24
+ Cluster string
25
+ Namespace string
26
+ }
27
+
28
+ SignCertificatesOptions struct {
29
+ AltName string
30
+ CSR string
31
+ }
32
+
21
33
createRuntimeEnvironmentResponse struct {
22
34
Name string
23
35
}
24
36
)
25
37
26
38
// CreateRuntimeEnvironment - create Runtime-Environment
27
39
func (c * codefresh ) CreateRuntimeEnvironment (opt * CreateRuntimeOptions ) (* RuntimeEnvironment , error ) {
28
- // r := &createRuntimeEnvironmentResponse{}
29
40
re := & RuntimeEnvironment {
30
41
Name : fmt .Sprintf ("%s/%s" , opt .Cluster , opt .Namespace ),
31
42
}
@@ -48,7 +59,35 @@ func (c *codefresh) CreateRuntimeEnvironment(opt *CreateRuntimeOptions) (*Runtim
48
59
49
60
if resp .StatusCode < 400 {
50
61
return re , nil
51
- } else {
52
- return nil , fmt .Errorf ("Error during runtime environment creation" )
53
62
}
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
54
93
}
0 commit comments