Skip to content

Commit

Permalink
use utils functions
Browse files Browse the repository at this point in the history
  • Loading branch information
lostbean committed Nov 17, 2023
1 parent b4247f6 commit 7634d73
Showing 1 changed file with 8 additions and 30 deletions.
38 changes: 8 additions & 30 deletions engine/server/engine/server/engine_rest_api_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,10 +82,7 @@ func toHttpApiContainerStatus(status types.ContainerStatus) api.ApiContainerStat
}
}

func toHttpApiEnclaveAPIContainerInfo(info *types.EnclaveAPIContainerInfo) api.EnclaveAPIContainerInfo {
if info == nil {
return api.EnclaveAPIContainerInfo{}
}
func toHttpApiEnclaveAPIContainerInfo(info types.EnclaveAPIContainerInfo) api.EnclaveAPIContainerInfo {
port := int(info.GrpcPortInsideEnclave)
return api.EnclaveAPIContainerInfo{
ContainerId: info.ContainerId,
Expand All @@ -95,10 +92,7 @@ func toHttpApiEnclaveAPIContainerInfo(info *types.EnclaveAPIContainerInfo) api.E
}
}

func toHttpApiApiContainerHostMachineInfo(info *types.EnclaveAPIContainerHostMachineInfo) api.EnclaveAPIContainerHostMachineInfo {
if info == nil {
return api.EnclaveAPIContainerHostMachineInfo{}
}
func toHttpApiApiContainerHostMachineInfo(info types.EnclaveAPIContainerHostMachineInfo) api.EnclaveAPIContainerHostMachineInfo {
port := int(info.GrpcPortOnHostMachine)
return api.EnclaveAPIContainerHostMachineInfo{
IpOnHostMachine: info.IpOnHostMachine,
Expand All @@ -118,33 +112,17 @@ func toHttpApiEnclaveMode(mode types.EnclaveMode) api.EnclaveMode {
}

func toHttpApiEnclaveInfo(info types.EnclaveInfo) api.EnclaveInfo {
containerInfo := toHttpApiEnclaveAPIContainerInfo(info.ApiContainerInfo)
apiHostMachine := toHttpApiApiContainerHostMachineInfo(info.ApiContainerHostMachineInfo)
containersStatus := toHttpApiEnclaveContainersStatus(info.EnclaveContainersStatus)
apiContainerStatus := toHttpApiContainerStatus(info.ApiContainerStatus)
mode := toHttpApiEnclaveMode(info.Mode)
return api.EnclaveInfo{
EnclaveUuid: info.EnclaveUuid,
ShortenedUuid: info.ShortenedUuid,
Name: info.Name,
ContainersStatus: containersStatus,
ApiContainerStatus: apiContainerStatus,
ApiContainerInfo: &containerInfo,
ApiContainerHostMachineInfo: &apiHostMachine,
ContainersStatus: toHttpApiEnclaveContainersStatus(info.EnclaveContainersStatus),
ApiContainerStatus: toHttpApiContainerStatus(info.ApiContainerStatus),
ApiContainerInfo: utils.MapPointer(info.ApiContainerInfo, toHttpApiEnclaveAPIContainerInfo),
ApiContainerHostMachineInfo: utils.MapPointer(info.ApiContainerHostMachineInfo, toHttpApiApiContainerHostMachineInfo),
CreationTime: info.CreationTime,
Mode: mode,
}
}

func toHttpApiEnclaveInfos(infos map[string]*types.EnclaveInfo) map[string]api.EnclaveInfo {
info_map := make(map[string]api.EnclaveInfo)
for key, info := range infos {
if info != nil {
grpc_info := toHttpApiEnclaveInfo(*info)
info_map[key] = grpc_info
}
Mode: toHttpApiEnclaveMode(info.Mode),
}
return info_map
}

func toHttpApiEnclaveIdentifiers(identifier *types.EnclaveIdentifiers) api.EnclaveIdentifiers {
Expand Down Expand Up @@ -185,7 +163,7 @@ func (engine EngineRuntime) GetEnclaves(ctx context.Context, request api.GetEncl
if err != nil {
return nil, stacktrace.Propagate(err, "An error occurred getting info for enclaves")
}
response := toHttpApiEnclaveInfos(infoForEnclaves)
response := utils.MapMapValues(infoForEnclaves, func(enclave *types.EnclaveInfo) api.EnclaveInfo { return toHttpApiEnclaveInfo(*enclave) })
return api.GetEnclaves200JSONResponse(response), nil
}

Expand Down

0 comments on commit 7634d73

Please sign in to comment.