2017-01-13 18:35:25 +00:00
|
|
|
package service
|
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"net/http"
|
|
|
|
|
2017-02-01 17:20:50 +00:00
|
|
|
"github.com/kolide/kolide/server/kolide"
|
2017-01-13 18:35:25 +00:00
|
|
|
"golang.org/x/net/context"
|
|
|
|
)
|
|
|
|
|
|
|
|
func decodeImportConfigRequest(ctx context.Context, r *http.Request) (interface{}, error) {
|
|
|
|
var req importRequest
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
// Unmarshal main config
|
|
|
|
conf := kolide.ImportConfig{
|
|
|
|
Packs: make(kolide.PackNameMap),
|
|
|
|
ExternalPacks: make(kolide.PackNameToPackDetails),
|
|
|
|
}
|
|
|
|
if err := json.Unmarshal([]byte(req.Config), &conf); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
// Unmarshal external packs
|
|
|
|
for packName, packConfig := range req.ExternalPackConfigs {
|
|
|
|
var pack kolide.PackDetails
|
|
|
|
if err := json.Unmarshal([]byte(packConfig), &pack); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
conf.ExternalPacks[packName] = pack
|
|
|
|
}
|
|
|
|
conf.GlobPackNames = req.GlobPackNames
|
|
|
|
return conf, nil
|
|
|
|
}
|