forked from Azure/azure-extensions-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unpublish.go
57 lines (49 loc) · 1.69 KB
/
unpublish.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
package main
import (
"bytes"
"text/template"
log "github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
)
func unpublishVersion(c *cli.Context) {
p := struct {
Namespace, Name, Version string
}{
Namespace: checkFlag(c, flNamespace.Name),
Name: checkFlag(c, flName.Name),
Version: checkFlag(c, flVersion.Name)}
isXMLExtension := c.Bool(flIsXMLExtension.Name)
buf := bytes.NewBufferString(`<?xml version="1.0" encoding="utf-8" ?>
<ExtensionImage xmlns="http://schemas.microsoft.com/windowsazure" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<!-- WARNING: Ordering of fields matter in this file. -->
<ProviderNameSpace>{{.Namespace}}</ProviderNameSpace>
<Type>{{.Name}}</Type>
<Version>{{.Version}}</Version>
<IsInternalExtension>true</IsInternalExtension>
`)
// All extension should be a JSON extension. The biggest offenders are
// PaaS extensions.
if !isXMLExtension {
buf.WriteString("<IsJsonExtension>true</IsJsonExtension>")
}
buf.WriteString("</ExtensionImage>")
tpl, err := template.New("unregisterManifest").Parse(buf.String())
if err != nil {
log.Fatalf("template parse error: %v", err)
}
var b bytes.Buffer
if err = tpl.Execute(&b, p); err != nil {
log.Fatalf("template execute error: %v", err)
}
cl := mkClient(checkFlag(c, flMgtURL.Name), checkFlag(c, flSubsID.Name), checkFlag(c, flSubsCert.Name))
op, err := cl.UpdateExtension(b.Bytes())
if err != nil {
log.Fatalf("UpdateExtension failed: %v", err)
}
lg := log.WithField("x-ms-operation-id", op)
lg.Info("UpdateExtension operation started.")
if err := cl.WaitForOperation(op); err != nil {
lg.Fatalf("UpdateExtension failed: %v", err)
}
lg.Info("UpdateExtension operation finished.")
}