@@ -10,11 +10,11 @@ import (
1010type (
1111 // IRuntimeEnvironmentAPI declers Codefresh runtime environment API
1212 IRuntimeEnvironmentAPI interface {
13- CreateRuntimeEnvironment (* CreateRuntimeOptions ) (* RuntimeEnvironment , error )
14- ValidateRuntimeEnvironment (* ValidateRuntimeOptions ) error
15- SignRuntimeEnvironmentCertificate (* SignCertificatesOptions ) ([]byte , error )
16- GetRuntimeEnvironment (string ) (* RuntimeEnvironment , error )
17- GetRuntimeEnvironments () ([]* RuntimeEnvironment , error )
13+ Create (* CreateRuntimeOptions ) (* RuntimeEnvironment , error )
14+ Validate (* ValidateRuntimeOptions ) error
15+ SignCertificate (* SignCertificatesOptions ) ([]byte , error )
16+ Get (string ) (* RuntimeEnvironment , error )
17+ List () ([]* RuntimeEnvironment , error )
1818 }
1919
2020 RuntimeEnvironment struct {
@@ -76,13 +76,21 @@ type (
7676 CSR string
7777 }
7878
79- createRuntimeEnvironmentResponse struct {
79+ CreateResponse struct {
8080 Name string
8181 }
82+
83+ runtimeEnvironment struct {
84+ codefresh Codefresh
85+ }
8286)
8387
84- // CreateRuntimeEnvironment - create Runtime-Environment
85- func (c * codefresh ) CreateRuntimeEnvironment (opt * CreateRuntimeOptions ) (* RuntimeEnvironment , error ) {
88+ func newRuntimeEnvironmentAPI (codefresh Codefresh ) IRuntimeEnvironmentAPI {
89+ return & runtimeEnvironment {codefresh }
90+ }
91+
92+ // Create - create Runtime-Environment
93+ func (r * runtimeEnvironment ) Create (opt * CreateRuntimeOptions ) (* RuntimeEnvironment , error ) {
8694 re := & RuntimeEnvironment {
8795 Metadata : RuntimeMetadata {
8896 Name : fmt .Sprintf ("%s/%s" , opt .Cluster , opt .Namespace ),
@@ -95,7 +103,7 @@ func (c *codefresh) CreateRuntimeEnvironment(opt *CreateRuntimeOptions) (*Runtim
95103 if opt .HasAgent {
96104 body ["agent" ] = true
97105 }
98- resp , err := c .requestAPI (& requestOptions {
106+ resp , err := r . codefresh .requestAPI (& requestOptions {
99107 path : "/api/custom_clusters/register" ,
100108 method : "POST" ,
101109 body : body ,
@@ -111,39 +119,39 @@ func (c *codefresh) CreateRuntimeEnvironment(opt *CreateRuntimeOptions) (*Runtim
111119 return nil , fmt .Errorf ("Error during runtime environment creation" )
112120}
113121
114- func (c * codefresh ) ValidateRuntimeEnvironment (opt * ValidateRuntimeOptions ) error {
122+ func (r * runtimeEnvironment ) Validate (opt * ValidateRuntimeOptions ) error {
115123 body := map [string ]interface {}{
116124 "clusterName" : opt .Cluster ,
117125 "namespace" : opt .Namespace ,
118126 }
119- _ , err := c .requestAPI (& requestOptions {
127+ _ , err := r . codefresh .requestAPI (& requestOptions {
120128 path : "/api/custom_clusters/validate" ,
121129 method : "POST" ,
122130 body : body ,
123131 })
124132 return err
125133}
126134
127- func (c * codefresh ) SignRuntimeEnvironmentCertificate (opt * SignCertificatesOptions ) ([]byte , error ) {
135+ func (r * runtimeEnvironment ) SignCertificate (opt * SignCertificatesOptions ) ([]byte , error ) {
128136 body := map [string ]interface {}{
129137 "reqSubjectAltName" : opt .AltName ,
130138 "csr" : opt .CSR ,
131139 }
132- resp , err := c .requestAPI (& requestOptions {
140+ resp , err := r . codefresh .requestAPI (& requestOptions {
133141 path : "/api/custom_clusters/signServerCerts" ,
134142 method : "POST" ,
135143 body : body ,
136144 })
137145 if err != nil {
138146 return nil , err
139147 }
140- return c .getBodyAsBytes (resp )
148+ return r . codefresh .getBodyAsBytes (resp )
141149}
142150
143- func (c * codefresh ) GetRuntimeEnvironment (name string ) (* RuntimeEnvironment , error ) {
151+ func (r * runtimeEnvironment ) Get (name string ) (* RuntimeEnvironment , error ) {
144152 re := & RuntimeEnvironment {}
145153 path := fmt .Sprintf ("/api/runtime-environments/%s" , url .PathEscape (name ))
146- resp , err := c .requestAPI (& requestOptions {
154+ resp , err := r . codefresh .requestAPI (& requestOptions {
147155 path : path ,
148156 method : "GET" ,
149157 qs : map [string ]string {
@@ -155,17 +163,17 @@ func (c *codefresh) GetRuntimeEnvironment(name string) (*RuntimeEnvironment, err
155163 fmt .Println (err .Error ())
156164 return nil , err
157165 }
158- c .decodeResponseInto (resp , re )
166+ r . codefresh .decodeResponseInto (resp , re )
159167 return re , nil
160168}
161169
162- func (c * codefresh ) GetRuntimeEnvironments () ([]* RuntimeEnvironment , error ) {
170+ func (r * runtimeEnvironment ) List () ([]* RuntimeEnvironment , error ) {
163171 emptySlice := make ([]* RuntimeEnvironment , 0 )
164- resp , err := c .requestAPI (& requestOptions {
172+ resp , err := r . codefresh .requestAPI (& requestOptions {
165173 path : "/api/runtime-environments" ,
166174 method : "GET" ,
167175 })
168- tokensAsBytes , err := c .getBodyAsBytes (resp )
176+ tokensAsBytes , err := r . codefresh .getBodyAsBytes (resp )
169177 if err != nil {
170178 return nil , err
171179 }
0 commit comments