mirror of
https://github.com/kubevela/kubevela.git
synced 2026-05-20 16:23:24 +00:00
73 lines
2.2 KiB
Go
73 lines
2.2 KiB
Go
/*
|
|
Copyright 2021 The KubeVela Authors.
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
you may not use this file except in compliance with the License.
|
|
You may obtain a copy of the License at
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
See the License for the specific language governing permissions and
|
|
limitations under the License.
|
|
*/
|
|
|
|
package apiserver
|
|
|
|
import (
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/oam-dev/kubevela/apis/types"
|
|
"github.com/oam-dev/kubevela/references/apiserver/apis"
|
|
"github.com/oam-dev/kubevela/references/apiserver/util"
|
|
"github.com/oam-dev/kubevela/references/common"
|
|
)
|
|
|
|
// AttachTrait attaches a trait to a component
|
|
func (s *APIServer) AttachTrait(c *gin.Context) {
|
|
var body apis.TraitBody
|
|
body.EnvName = c.Param("envName")
|
|
body.AppName = c.Param("appName")
|
|
body.ComponentName = c.Param("compName")
|
|
|
|
if err := c.ShouldBindJSON(&body); err != nil {
|
|
util.HandleError(c, util.InvalidArgument, "the trait attach request body is invalid")
|
|
return
|
|
}
|
|
|
|
util.AssembleResponse(c, "deprecated, please use appfile to update", nil)
|
|
}
|
|
|
|
// GetTrait gets a trait by name
|
|
func (s *APIServer) GetTrait(c *gin.Context) {
|
|
var traitType = c.Param("traitName")
|
|
var workloadType string
|
|
var capability types.Capability
|
|
var err error
|
|
|
|
if capability, err = common.GetTraitDefinition("default", s.c, &workloadType, traitType); err != nil {
|
|
util.HandleError(c, util.StatusInternalServerError, err)
|
|
return
|
|
}
|
|
util.AssembleResponse(c, capability, err)
|
|
}
|
|
|
|
// ListTrait lists all traits
|
|
func (s *APIServer) ListTrait(c *gin.Context) {
|
|
var traitList []types.Capability
|
|
var workloadName string
|
|
var err error
|
|
if traitList, err = common.ListTraitDefinitions("default", s.c, &workloadName); err != nil {
|
|
util.HandleError(c, util.StatusInternalServerError, err)
|
|
return
|
|
}
|
|
util.AssembleResponse(c, traitList, err)
|
|
}
|
|
|
|
// DetachTrait detaches a trait from a component
|
|
func (s *APIServer) DetachTrait(c *gin.Context) {
|
|
util.AssembleResponse(c, "deprecated, please use appfile to update", nil)
|
|
}
|