diff --git a/src/api/rest/docs/docs.go b/src/api/rest/docs/docs.go index e19eef391..5fccdf32c 100644 --- a/src/api/rest/docs/docs.go +++ b/src/api/rest/docs/docs.go @@ -6724,7 +6724,7 @@ const docTemplate = `{ }, "/ns/{nsId}/resources/image/{imageId}": { "get": { - "description": "Get image", + "description": "GetImage returns an image object if there are matched images for the given namespace and imageKey(Id, CspResourceName, GuestOS,...)", "consumes": [ "application/json" ], @@ -6747,7 +6747,7 @@ const docTemplate = `{ }, { "type": "string", - "description": "Image ID ({providerName}+{regionName}+{cspImageName})", + "description": "(Note: imageId param will be refined in next release, enabled for temporal support) This param accepts vaious input types as Image Key: [1. registerd ID: ({providerName}+{regionName}+{GuestOS}). 2. cspImageName. 3. GuestOS)]", "name": "imageId", "in": "path", "required": true diff --git a/src/api/rest/docs/swagger.json b/src/api/rest/docs/swagger.json index 51c1ba647..2ace720b3 100644 --- a/src/api/rest/docs/swagger.json +++ b/src/api/rest/docs/swagger.json @@ -6717,7 +6717,7 @@ }, "/ns/{nsId}/resources/image/{imageId}": { "get": { - "description": "Get image", + "description": "GetImage returns an image object if there are matched images for the given namespace and imageKey(Id, CspResourceName, GuestOS,...)", "consumes": [ "application/json" ], @@ -6740,7 +6740,7 @@ }, { "type": "string", - "description": "Image ID ({providerName}+{regionName}+{cspImageName})", + "description": "(Note: imageId param will be refined in next release, enabled for temporal support) This param accepts vaious input types as Image Key: [1. registerd ID: ({providerName}+{regionName}+{GuestOS}). 2. cspImageName. 3. GuestOS)]", "name": "imageId", "in": "path", "required": true diff --git a/src/api/rest/docs/swagger.yaml b/src/api/rest/docs/swagger.yaml index 2bfa1b161..bf45d57b6 100644 --- a/src/api/rest/docs/swagger.yaml +++ b/src/api/rest/docs/swagger.yaml @@ -5097,7 +5097,8 @@ paths: tags: - "[Infra Resource] Image Management" summary: Get image - description: Get image + description: "GetImage returns an image object if there are matched images for\ + \ the given namespace and imageKey(Id, CspResourceName, GuestOS,...)" operationId: GetImage parameters: - name: nsId @@ -5109,7 +5110,10 @@ paths: default: system - name: imageId in: path - description: "Image ID ({providerName}+{regionName}+{cspImageName})" + description: "(Note: imageId param will be refined in next release, enabled\ + \ for temporal support) This param accepts vaious input types as Image Key:\ + \ [1. registerd ID: ({providerName}+{regionName}+{GuestOS}). 2. cspImageName.\ + \ 3. GuestOS)]" required: true schema: type: string diff --git a/src/api/rest/server/resource/image.go b/src/api/rest/server/resource/image.go index f16453755..061c73506 100644 --- a/src/api/rest/server/resource/image.go +++ b/src/api/rest/server/resource/image.go @@ -215,19 +215,24 @@ func RestFetchImages(c echo.Context) error { // RestGetImage godoc // @ID GetImage // @Summary Get image -// @Description Get image +// @Description GetImage returns an image object if there are matched images for the given namespace and imageKey(Id, CspResourceName, GuestOS,...) // @Tags [Infra Resource] Image Management // @Accept json // @Produce json // @Param nsId path string true "Namespace ID" default(system) -// @Param imageId path string true "Image ID ({providerName}+{regionName}+{cspImageName})" +// @Param imageId path string true "(Note: imageId param will be refined in next release, enabled for temporal support) This param accepts vaious input types as Image Key: [1. registerd ID: ({providerName}+{regionName}+{GuestOS}). 2. cspImageName. 3. GuestOS)]" // @Success 200 {object} model.TbImageInfo // @Failure 404 {object} model.SimpleMsg // @Failure 500 {object} model.SimpleMsg // @Router /ns/{nsId}/resources/image/{imageId} [get] func RestGetImage(c echo.Context) error { - // This is a dummy function for Swagger. - return nil + nsId := c.Param("nsId") + imageKey := c.Param("imageId") + imageKey = strings.ReplaceAll(imageKey, " ", "+") + imageKey = strings.ReplaceAll(imageKey, "%2B", "+") + + content, err := resource.GetImage(nsId, imageKey) + return common.EndRequestWithLog(c, err, content) } // Response structure for RestGetAllImage diff --git a/src/api/rest/server/server.go b/src/api/rest/server/server.go index 049c15484..471f90baa 100644 --- a/src/api/rest/server/server.go +++ b/src/api/rest/server/server.go @@ -423,9 +423,9 @@ func RunServer() { g.PUT("/:nsId/mci/:mciId/vm/:vmId/dataDisk", rest_resource.RestPutVmDataDisk) g.POST("/:nsId/resources/image", rest_resource.RestPostImage) - g.GET("/:nsId/resources/image/:resourceId", rest_resource.RestGetResource) + g.GET("/:nsId/resources/image/:imageId", rest_resource.RestGetImage) g.GET("/:nsId/resources/image", rest_resource.RestGetAllResources) - g.PUT("/:nsId/resources/image/:resourceId", rest_resource.RestPutImage) + g.PUT("/:nsId/resources/image/:imageId", rest_resource.RestPutImage) g.DELETE("/:nsId/resources/image/:resourceId", rest_resource.RestDelResource) g.DELETE("/:nsId/resources/image", rest_resource.RestDelAllResources) diff --git a/src/core/resource/image.go b/src/core/resource/image.go index f43de7f0c..0d2cd0b80 100644 --- a/src/core/resource/image.go +++ b/src/core/resource/image.go @@ -552,7 +552,7 @@ func UpdateImage(nsId string, imageId string, fieldsToUpdate model.TbImageInfo, return fieldsToUpdate, nil } -// GetImage accepts namespace Id and imageKey(Id,CspResourceId,GuestOS,...), and returns the TB image object +// GetImage accepts namespace Id and imageKey(Id,CspResourceName,GuestOS,...), and returns the TB image object func GetImage(nsId string, imageKey string) (model.TbImageInfo, error) { if err := common.CheckString(nsId); err != nil { log.Error().Err(err).Msg("Invalid namespace ID") @@ -577,9 +577,9 @@ func GetImage(nsId string, imageKey string) (model.TbImageInfo, error) { // ex: img-487zeit5 image = model.TbImageInfo{Namespace: nsId, CspImageName: imageKey} - has, err = model.ORM.Where("LOWER(Namespace) = ? AND LOWER(CspResourceId) = ?", nsId, imageKey).Get(&image) + has, err = model.ORM.Where("LOWER(Namespace) = ? AND LOWER(CspImageName) = ?", nsId, imageKey).Get(&image) if err != nil { - log.Info().Err(err).Msgf("Failed to get image %s by CspResourceId", imageKey) + log.Info().Err(err).Msgf("Failed to get image %s by CspImageName", imageKey) } if has { return image, nil @@ -595,5 +595,5 @@ func GetImage(nsId string, imageKey string) (model.TbImageInfo, error) { return image, nil } - return model.TbImageInfo{}, fmt.Errorf("The imageKey %s not found by any of ID, CspResourceId, GuestOS", imageKey) + return model.TbImageInfo{}, fmt.Errorf("The imageKey %s not found by any of ID, CspImageName, GuestOS", imageKey) } diff --git a/src/core/resource/spec.go b/src/core/resource/spec.go index a6050791b..df61940d3 100644 --- a/src/core/resource/spec.go +++ b/src/core/resource/spec.go @@ -370,7 +370,7 @@ type Range struct { Max float32 `json:"max"` } -// GetSpec accepts namespace Id and specKey(Id,CspResourceId,...), and returns the TB spec object +// GetSpec accepts namespace Id and specKey(Id,CspResourceName,...), and returns the TB spec object func GetSpec(nsId string, specKey string) (model.TbSpecInfo, error) { if err := common.CheckString(nsId); err != nil { log.Error().Err(err).Msg("Invalid namespace ID") @@ -395,15 +395,15 @@ func GetSpec(nsId string, specKey string) (model.TbSpecInfo, error) { // ex: img-487zeit5 spec = model.TbSpecInfo{Namespace: nsId, CspSpecName: specKey} - has, err = model.ORM.Where("LOWER(Namespace) = ? AND LOWER(CspResourceId) = ?", nsId, specKey).Get(&spec) + has, err = model.ORM.Where("LOWER(Namespace) = ? AND LOWER(CspResourceName) = ?", nsId, specKey).Get(&spec) if err != nil { - log.Info().Err(err).Msgf("Failed to get spec %s by CspResourceId", specKey) + log.Info().Err(err).Msgf("Failed to get spec %s by CspResourceName", specKey) } if has { return spec, nil } - return model.TbSpecInfo{}, fmt.Errorf("The specKey %s not found by any of ID, CspResourceId", specKey) + return model.TbSpecInfo{}, fmt.Errorf("The specKey %s not found by any of ID, CspResourceName", specKey) } // FilterSpecsByRange accepts criteria ranges for filtering, and returns the list of filtered TB spec objects