@@ -221,7 +221,7 @@ func (c *Client) AddCompanyOwners(ctx context.Context, company corev1alpha1.Comp
221221 return errors
222222}
223223
224- func (c * Client ) AddCompanyCluster (ctx context.Context , cluster corev1alpha1.Cluster , companyId string , serviceAccountToken string ) error {
224+ func (c * Client ) AddCompanyCluster (ctx context.Context , cluster corev1alpha1.Cluster , companyId string , serviceAccountToken string ) ( string , error ) {
225225
226226 var log = log .Default ()
227227 addClusterURL := fmt .Sprintf ("/api/tenants/%s/clusters/" , companyId )
@@ -243,12 +243,33 @@ func (c *Client) AddCompanyCluster(ctx context.Context, cluster corev1alpha1.Clu
243243 log .Printf ("Adding cluster %s to company %s. Calling URL %s" , cluster .ClusterId , companyId , addClusterURL )
244244 log .Printf ("Payload %s" , clusterPayload )
245245
246- if err := c .PostJSON (ctx , addClusterURL , clusterPayload , nil ); err != nil {
246+ var result struct {
247+ ClusterId string `json:"_id"`
248+ }
249+ if err := c .PostJSON (ctx , addClusterURL , clusterPayload , & result ); err != nil {
247250 log .Printf ("Error %s" , err )
248- return err
251+ return "" , err
249252 }
250- return nil
251253
254+ return result .ClusterId , nil
255+ }
256+
257+ func (c * Client ) AddCompanyEnvironments (ctx context.Context , environments []corev1alpha1.Environment , companyId string , clusters map [string ]string ) error {
258+ var log = log .Default ()
259+ var addEnvPath = fmt .Sprintf ("/tenants/%s/project-blueprint/environments" , companyId )
260+ var environmentsPayload []corev1alpha1.Environment = []corev1alpha1.Environment {}
261+ for _ , env := range environments {
262+ clusterId , exists := clusters [env .Cluster .ClusterId ]
263+ if exists && clusterId != "" {
264+ env .Cluster .ClusterId = clusterId
265+ environmentsPayload = append (environmentsPayload , env )
266+ } else {
267+ log .Fatal ("ClusterId not found for environment " , env .EnvId , " with cluster " , env .Cluster .ClusterId )
268+ }
269+ }
270+ log .Printf ("Adding environments to company %s. Calling URL %s" , companyId , addEnvPath )
271+ log .Printf ("Payload %+v" , environmentsPayload )
272+ return c .PostJSON (ctx , addEnvPath , environmentsPayload , nil )
252273}
253274
254275// PostJSON is a convenience method that performs POST and unmarshals JSON response
0 commit comments