@@ -48,15 +48,18 @@ type OrgoComputerCreateRequest struct {
4848}
4949
5050type OrgoComputerResponse struct {
51- ID string `json:"id"`
52- Name string `json:"name"`
53- ProjectName string `json:"project_name"`
54- OS string `json:"os"`
55- RAM int `json:"ram"`
56- CPU int `json:"cpu"`
57- Status string `json:"status"`
58- URL string `json:"url"`
59- CreatedAt string `json:"created_at"`
51+ ID string `json:"id"`
52+ Name string `json:"name"`
53+ ProjectName string `json:"project_name"`
54+ OS string `json:"os"`
55+ RAM int `json:"ram"`
56+ CPU int `json:"cpu"`
57+ Status string `json:"status"`
58+ URL string `json:"url"`
59+ CreatedAt string `json:"created_at"`
60+ Region string `json:"region"`
61+ InstanceType string `json:"instance_type"`
62+ Hostname string `json:"hostname"`
6063}
6164
6265type OrgoProjectResponse struct {
@@ -239,52 +242,42 @@ func (p *OrgoProvider) WaitForInstanceReady(httpClient *http.Client, apiToken st
239242// GetInstance retrieves details for a specific computer
240243func (p * OrgoProvider ) GetInstance (httpClient * http.Client , apiToken string , instanceID string ) (* RunningInstance , error ) {
241244 url := fmt .Sprintf ("https://www.orgo.ai/api/computers/%s" , instanceID )
242-
243245 req , err := http .NewRequest ("GET" , url , nil )
244246 if err != nil {
245247 return nil , fmt .Errorf ("failed to create request: %w" , err )
246248 }
247249 req .Header .Set ("Authorization" , fmt .Sprintf ("Bearer %s" , apiToken ))
248-
249250 resp , err := httpClient .Do (req )
250251 if err != nil {
251252 return nil , fmt .Errorf ("failed to execute request: %w" , err )
252253 }
253254 defer resp .Body .Close ()
254- var body []byte
255- if resp .StatusCode != http .StatusOK {
256- body , _ = io .ReadAll (resp .Body )
257- return nil , fmt .Errorf ("API request failed with status %d: %s" , resp .StatusCode , string (body ))
258- }
259-
260- body , err = io .ReadAll (resp .Body )
255+ body , err := io .ReadAll (resp .Body )
261256 if err != nil {
262257 return nil , fmt .Errorf ("failed to read response body: %w" , err )
263258 }
264259
265260 var apiResponse struct {
266261 Data OrgoComputerResponse `json:"data"`
267262 }
268-
269263 err = json .Unmarshal (body , & apiResponse )
270264 if err != nil {
271265 return nil , fmt .Errorf ("failed to unmarshal response: %w" , err )
272266 }
273-
274- // Convert Orgo response to RunningInstance format
275267 runningInstance := & RunningInstance {
276268 ID : apiResponse .Data .ID ,
277269 Name : apiResponse .Data .Name ,
278270 Status : apiResponse .Data .Status ,
279- IP : "" , // Orgo doesn't provide direct IP access
280- InstanceType : InstanceType {
281- Name : fmt .Sprintf ("%dgb" , apiResponse .Data .RAM ),
282- },
283271 Region : Region {
284- Name : apiResponse .Data .ProjectName ,
272+ Name : apiResponse .Data .Region ,
273+ Description : "" ,
274+ },
275+ InstanceType : InstanceType {
276+ Name : apiResponse .Data .InstanceType ,
277+ Description : "" ,
285278 },
279+ Hostname : apiResponse .Data .Hostname ,
286280 }
287-
288281 return runningInstance , nil
289282}
290283
@@ -293,9 +286,11 @@ func (p *OrgoProvider) ListRunningInstances(httpClient *http.Client, apiToken st
293286 // First get all projects
294287 projects , err := p .listProjects (httpClient , apiToken )
295288 if err != nil {
289+
296290 return nil , fmt .Errorf ("failed to list projects: %w" , err )
297291 }
298292
293+ var body []byte
299294 var allInstances []RunningInstance
300295
301296 // For each project, list computers
@@ -405,24 +400,20 @@ func (p *OrgoProvider) TerminateInstance(httpClient *http.Client, apiToken strin
405400
406401// Helper methods
407402
408- func (p * OrgoProvider ) ensureProjectExists (httpClient * http.Client , apiToken string , projectName string ) error {
409- // Try to get the project first
410- url := fmt .Sprintf ("https://www.orgo.ai/api/projects/by-name/%s" , projectName )
411-
403+ func (p * OrgoProvider ) checkProjectExists (httpClient * http.Client , apiToken string , projectName string ) error {
404+ url := fmt .Sprintf ("https://www.orgo.ai/api/projects/%s" , url .PathEscape (projectName ))
412405 req , err := http .NewRequest ("GET" , url , nil )
413406 if err != nil {
414407 return fmt .Errorf ("failed to create request: %w" , err )
415408 }
416409 req .Header .Set ("Authorization" , fmt .Sprintf ("Bearer %s" , apiToken ))
417-
418410 resp , err := httpClient .Do (req )
419411 if err != nil {
420412 return fmt .Errorf ("failed to execute request: %w" , err )
421413 }
422414 defer resp .Body .Close ()
423415 var body []byte
424416 if resp .StatusCode == http .StatusOK {
425- // Project exists
426417 return nil
427418 }
428419
@@ -431,31 +422,23 @@ func (p *OrgoProvider) ensureProjectExists(httpClient *http.Client, apiToken str
431422 return fmt .Errorf ("unexpected response when checking project: %s" , string (body ))
432423 }
433424
434- // Project doesn't exist, create it
435- return p .createProject (httpClient , apiToken , projectName )
436- }
437-
438- func (p * OrgoProvider ) createProject (httpClient * http.Client , apiToken string , projectName string ) error {
439425 requestBody := OrgoProjectCreateRequest {Name : projectName }
440-
441426 jsonBody , err := json .Marshal (requestBody )
442427 if err != nil {
443428 return fmt .Errorf ("failed to marshal request body: %w" , err )
444429 }
445-
446- req , err := http .NewRequest ("POST" , "https://www.orgo.ai/api/projects" , strings .NewReader (string (jsonBody )))
430+ req , err = http .NewRequest ("POST" , "https://www.orgo.ai/api/projects" , strings .NewReader (string (jsonBody )))
447431 if err != nil {
448432 return fmt .Errorf ("failed to create request: %w" , err )
449433 }
450434 req .Header .Set ("Authorization" , fmt .Sprintf ("Bearer %s" , apiToken ))
451435 req .Header .Set ("Content-Type" , "application/json" )
452436
453- resp , err : = httpClient .Do (req )
437+ resp , err = httpClient .Do (req )
454438 if err != nil {
455439 return fmt .Errorf ("failed to execute request: %w" , err )
456440 }
457441 defer resp .Body .Close ()
458- var body []byte
459442 if resp .StatusCode != http .StatusOK {
460443 body , _ = io .ReadAll (resp .Body )
461444 return fmt .Errorf ("API request failed with status %d: %s" , resp .StatusCode , string (body ))
@@ -474,7 +457,7 @@ func (p *OrgoProvider) createComputer(httpClient *http.Client, apiToken string,
474457
475458 jsonBody , err := json .Marshal (requestBody )
476459 if err != nil {
477- return "" , fmt .Errorf ("failed to marshal request body: %w" , err )
460+ return "" , fmt .Errorf ("faied to marshal request body: %w" , err )
478461 }
479462
480463 // Use project name with /computers endpoint per API docs (URL-encode for spaces/special chars)
@@ -492,9 +475,8 @@ func (p *OrgoProvider) createComputer(httpClient *http.Client, apiToken string,
492475 return "" , fmt .Errorf ("failed to execute request: %w" , err )
493476 }
494477 defer resp .Body .Close ()
495-
496-
497478 var body []byte
479+
498480 if resp .StatusCode != http .StatusOK {
499481 body , _ = io .ReadAll (resp .Body )
500482 return "" , fmt .Errorf ("API request failed with status %d: %s" , resp .StatusCode , string (body ))
0 commit comments