-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
131 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
[ | ||
{ | ||
"flavor": "medium", | ||
"fqdn": "server01.mycompany.com", | ||
"id": "123", | ||
"ipv4": "192.168.0.26", | ||
"name": "server01", | ||
"scopes": { | ||
"geo": { | ||
"label": "Paris 01", | ||
"value": "par-01" | ||
}, | ||
"logical": { | ||
"label": "Project 1", | ||
"value": "project-1" | ||
} | ||
}, | ||
"ssh": { | ||
"keyName": "keypair-01", | ||
"port": 22, | ||
"username": "admin" | ||
}, | ||
"stack": "nodejs", | ||
"status": "off" | ||
}, | ||
{ | ||
"flavor": "medium", | ||
"fqdn": "server02.mycompany.com", | ||
"id": "456", | ||
"ipv4": "192.168.0.27", | ||
"name": "server02", | ||
"scopes": { | ||
"geo": { | ||
"label": "Paris 01", | ||
"value": "par-01" | ||
}, | ||
"logical": { | ||
"label": "Project 1", | ||
"value": "project-1" | ||
} | ||
}, | ||
"ssh": { | ||
"keyName": "keypair-01", | ||
"port": 22, | ||
"username": "admin" | ||
}, | ||
"stack": "go", | ||
"status": "off" | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"io" | ||
"log/slog" | ||
"openapi" | ||
"os" | ||
) | ||
|
||
type ServiceFileJson struct { | ||
config *Config | ||
logger *slog.Logger | ||
} | ||
|
||
func (service ServiceFileJson) list(params *openapi.ListRunnablesQueryParams) (*ServiceError, *openapi.ListResRunnable) { | ||
config := service.config | ||
|
||
file, err := os.Open(*config.serviceFileJsonFilePath) | ||
if err != nil { | ||
return &ServiceError{HttpStatus: 500, Message: err.Error()}, nil | ||
} | ||
|
||
defer file.Close() | ||
|
||
content, err := io.ReadAll(file) | ||
if err != nil { | ||
return &ServiceError{HttpStatus: 500, Message: err.Error()}, nil | ||
} | ||
|
||
var items []openapi.Runnable | ||
json.Unmarshal(content, &items) | ||
if items == nil { | ||
return &ServiceError{HttpStatus: 500, Message: "Fix your JSON file to respect the schema"}, nil | ||
} | ||
|
||
total := int32(len(items)) | ||
|
||
res := openapi.NewListResRunnable(items, total) | ||
|
||
return nil, res | ||
} | ||
|
||
func (service ServiceFileJson) reboot(id string) (*ServiceError, *openapi.RunnableOperationRes) { | ||
return nil, openapi.NewRunnableOperationRes(*openapi.NewNullableString(nil)) | ||
} | ||
|
||
func (service ServiceFileJson) stop(id string) (*ServiceError, *openapi.RunnableOperationRes) { | ||
return nil, openapi.NewRunnableOperationRes(*openapi.NewNullableString(nil)) | ||
} |