Created
May 13, 2017 15:57
-
-
Save maleck13/6c0e7686f75c18dba599efa1378a4947 to your computer and use it in GitHub Desktop.
attempt to decode OSCP template
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package template | |
import ( | |
"github.com/pkg/errors" | |
kapi "k8s.io/kubernetes/pkg/api" | |
kapi1 "k8s.io/kubernetes/pkg/api/v1" | |
"k8s.io/kubernetes/pkg/runtime" | |
"io/ioutil" | |
"fmt" | |
buildconfig "github.com/openshift/origin/pkg/build/api" | |
buildconfig1 "github.com/openshift/origin/pkg/build/api/v1" | |
dc "github.com/openshift/origin/pkg/deploy/api" | |
dcv1 "github.com/openshift/origin/pkg/deploy/api/v1" | |
ioapi "github.com/openshift/origin/pkg/image/api" | |
ioapi1 "github.com/openshift/origin/pkg/image/api/v1" | |
roapi "github.com/openshift/origin/pkg/route/api" | |
roapi1 "github.com/openshift/origin/pkg/route/api/v1" | |
template "github.com/openshift/origin/pkg/template/api" | |
template1 "github.com/openshift/origin/pkg/template/api/v1" | |
) | |
func init() { | |
template.AddToScheme(kapi.Scheme) | |
template1.AddToScheme(kapi.Scheme) | |
kapi1.AddToScheme(kapi.Scheme) | |
buildconfig.AddToScheme(kapi.Scheme) | |
buildconfig1.AddToScheme(kapi.Scheme) | |
dc.AddToScheme(kapi.Scheme) | |
dcv1.AddToScheme(kapi.Scheme) | |
roapi.AddToScheme(kapi.Scheme) | |
roapi1.AddToScheme(kapi.Scheme) | |
ioapi.AddToScheme(kapi.Scheme) | |
ioapi1.AddToScheme(kapi.Scheme) | |
} | |
type Parser struct { | |
} | |
func (p *Parser) ParseOpenShiftTemplate(templatePath string) (*template.Template, error) { | |
// we care about services, deployments, routes, volumes | |
data, err := ioutil.ReadFile(templatePath) | |
if err != nil { | |
return nil, errors.Wrap(err, " failed to read template file ") | |
} | |
dec := kapi.Codecs.UniversalDecoder() | |
obj, _, err := dec.Decode(data, nil, nil) | |
if err != nil { | |
return nil, errors.Wrap(err, "failed to decode template ") | |
} | |
tmpl, ok := obj.(*template.Template) | |
if !ok { | |
return nil, fmt.Errorf("top level object must be of kind Template") | |
} | |
fmt.Println(len(tmpl.Objects)) | |
errs := runtime.DecodeList(tmpl.Objects, dec) | |
fmt.Println(len(tmpl.Objects)) | |
if len(errs) > 0 { | |
return nil, errs[0] | |
} | |
return tmpl, err | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment