本文整理汇总了Golang中mig/ninja/mig.ManifestParameters.Validate方法的典型用法代码示例。如果您正苦于以下问题:Golang ManifestParameters.Validate方法的具体用法?Golang ManifestParameters.Validate怎么用?Golang ManifestParameters.Validate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mig/ninja/mig.ManifestParameters
的用法示例。
在下文中一共展示了ManifestParameters.Validate方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: getAgentManifest
// This API entry point is used by the loader to request a manifest file that
// indicates the most current version of the agent to be used. The loader
// sends some basic information in the request parameters so the API can decide
// which manifest to send the loader.
//
// If the key passed in the request is not valid, the request will be rejected.
func getAgentManifest(respWriter http.ResponseWriter, request *http.Request) {
loc := fmt.Sprintf("%s%s", ctx.Server.Host, request.URL.String())
opid := getOpID(request)
resource := cljs.New(loc)
defer func() {
if e := recover(); e != nil {
ctx.Channels.Log <- mig.Log{OpID: opid, Desc: fmt.Sprintf("%v", e)}.Err()
resource.SetError(cljs.Error{Code: fmt.Sprintf("%.0f", opid), Message: fmt.Sprintf("%v", e)})
respond(http.StatusInternalServerError, resource, respWriter, request)
}
ctx.Channels.Log <- mig.Log{OpID: opid, Desc: "leaving getAgentManifest()"}.Debug()
}()
err := request.ParseForm()
if err != nil {
panic(err)
}
ctx.Channels.Log <- mig.Log{OpID: opid, Desc: "Received manifest request"}.Debug()
var manifestParam mig.ManifestParameters
err = json.Unmarshal([]byte(request.FormValue("parameters")), &manifestParam)
if err != nil {
panic(err)
}
err = manifestParam.Validate()
if err != nil {
panic(err)
}
loaderid := getLoaderID(request)
if loaderid == 0 {
panic("Request has no valid loader ID")
}
// Update the loader entry with the parameters, and locate a valid manifest
mf, err := locateManifestFromLoader(loaderid, manifestParam.AgentIdentifier)
if err != nil {
panic(err)
}
m, err := mf.ManifestResponse()
if err != nil {
panic(err)
}
// Include the loader ID with the response
m.LoaderName, err = ctx.DB.GetLoaderName(loaderid)
if err != nil {
panic(err)
}
// Send the manifest to the loader
err = resource.AddItem(cljs.Item{
Href: request.URL.String(),
Data: []cljs.Data{
{
Name: "manifest",
Value: m,
},
}})
if err != nil {
panic(err)
}
respond(http.StatusOK, resource, respWriter, request)
}