fleet/server/service/transport_import_config.go

35 lines
882 B
Go
Raw Normal View History

package service
import (
"encoding/json"
"net/http"
2017-02-01 17:20:50 +00:00
"github.com/kolide/kolide/server/kolide"
"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
}