forked from Azure/azure-extensions-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manifest.go
176 lines (155 loc) · 6.59 KB
/
manifest.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
package main
import (
"encoding/xml"
"fmt"
log "github.com/Sirupsen/logrus"
"github.com/codegangsta/cli"
"io/ioutil"
"strings"
)
type certificate struct {
StoreLocation string `xml:"StoreLocation,omitempty"`
StoreName string `xml:"StoreName,omitempty"`
ThumbprintRequired bool `xml:"ThumbprintRequired,omitempty"`
ThumbprintAlgorithm string `xml:"ThumbprintAlgorithm,omitempty"`
}
// NOTE(@boumenot): there is probably a better way to express this. If
// you know please share...
//
// The only difference between ExtensionImage and ExtensionImageGlobal is the
// Regions element. This element can be in three different states to my
// knowledge.
//
// 1. not defined
// 2. <Regions>Region1;Region2</Regions>
// 3. <Regions></Regions>
//
// Case (1) occurs when an extension is first published. Case(2) occurs when
// an extension is promoted to one or two regions. Case (3) occurs when an
// extension is published to all regions.
//
// I do not know how to express all three cases using Go's XML serializer.
//
type extensionImage struct {
XMLName string `xml:"ExtensionImage"`
NS string `xml:"xmlns,attr"`
ProviderNameSpace string `xml:"ProviderNameSpace"`
Type string `xml:"Type"`
Version string `xml:"Version"`
Label string `xml:"Label"`
HostingResources string `xml:"HostingResources"`
MediaLink string `xml:"MediaLink"`
Endpoints string `xml:"Endpoints"`
Certificate *certificate `xml:"Certificate,omitempty"`
PublicConfigurationSchema string `xml:"PublicConfigurationSchema,omitempty"`
PrivateConfigurationSchema string `xml:"PrivateConfigurationSchema,omitempty"`
Description string `xml:"Description"`
LocalResources string `xml:"LocalResources"`
BlockRoleUponFailure string `xml:"BlockRoleUponFailure,omitempty"`
IsInternalExtension bool `xml:"IsInternalExtension"`
Eula string `xml:"Eula,omitempty"`
PrivacyURI string `xml:"PrivacyUri,omitempty"`
HomepageURI string `xml:"HomepageUri,omitempty"`
IsJSONExtension bool `xml:"IsJsonExtension,omitempty"`
DisallowMajorVersionUpgrade bool `xml:"DisallowMajorVersionUpgrade,omitempty"`
CompanyName string `xml:"CompanyName,omitempty"`
SupportedOS string `xml:"SupportedOS,omitempty"`
Regions string `xml:"Regions,omitempty"`
}
type extensionImageGlobal struct {
XMLName string `xml:"ExtensionImage"`
NS string `xml:"xmlns,attr"`
ProviderNameSpace string `xml:"ProviderNameSpace"`
Type string `xml:"Type"`
Version string `xml:"Version"`
Label string `xml:"Label"`
HostingResources string `xml:"HostingResources"`
Endpoints string `xml:"Endpoints"`
MediaLink string `xml:"MediaLink"`
Certificate *certificate `xml:"Certificate,omitempty"`
PublicConfigurationSchema string `xml:"PublicConfigurationSchema,omitempty"`
PrivateConfigurationSchema string `xml:"PrivateConfigurationSchema,omitempty"`
Description string `xml:"Description"`
LocalResources string `xml:"LocalResources"`
BlockRoleUponFailure string `xml:"BlockRoleUponFailure,omitempty"`
IsInternalExtension bool `xml:"IsInternalExtension"`
Eula string `xml:"Eula,omitempty"`
PrivacyURI string `xml:"PrivacyUri,omitempty"`
HomepageURI string `xml:"HomepageUri,omitempty"`
IsJSONExtension bool `xml:"IsJsonExtension,omitempty"`
DisallowMajorVersionUpgrade bool `xml:"DisallowMajorVersionUpgrade,omitempty"`
CompanyName string `xml:"CompanyName,omitempty"`
SupportedOS string `xml:"SupportedOS,omitempty"`
Regions string `xml:"Regions"`
}
type extensionManifest interface {
Marshal() ([]byte, error)
}
func isGuestAgent(providerNameSpace string) bool {
return "Microsoft.OSTCLinuxAgent" == providerNameSpace
}
func newExtensionImageManifest(filename string, regions []string) (extensionManifest, error) {
b, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
var manifest extensionImage
err = xml.Unmarshal(b, &manifest)
if err != nil {
return nil, err
}
manifest.Regions = strings.Join(regions, ";")
manifest.IsInternalExtension = isGuestAgent(manifest.ProviderNameSpace)
return &manifest, nil
}
func newExtensionImageGlobalManifest(filename string) (extensionManifest, error) {
b, err := ioutil.ReadFile(filename)
if err != nil {
return nil, err
}
var manifest extensionImageGlobal
err = xml.Unmarshal(b, &manifest)
if err != nil {
return nil, err
}
manifest.IsInternalExtension = isGuestAgent(manifest.ProviderNameSpace)
return &manifest, nil
}
func (ext *extensionImage) Marshal() ([]byte, error) {
return xml.Marshal(*ext)
}
func (ext *extensionImageGlobal) Marshal() ([]byte, error) {
return xml.Marshal(*ext)
}
func newExtensionManifest(c *cli.Context) {
cl := mkClient(checkFlag(c, flMgtURL.Name), checkFlag(c, flSubsID.Name), checkFlag(c, flSubsCert.Name))
storageRealm := checkFlag(c, flStorageRealm.Name)
storageAccount := checkFlag(c, flStorageAccount.Name)
extensionPkg := checkFlag(c, flPackage.Name)
// Upload extension blob
blobURL, err := uploadBlob(cl, storageRealm, storageAccount, extensionPkg)
if err != nil {
log.Fatal(err)
}
log.Debugf("Extension package uploaded to: %s", blobURL)
manifest := extensionImage{
ProviderNameSpace: checkFlag(c, flNamespace.Name),
Type: checkFlag(c, flName.Name),
Version: checkFlag(c, flVersion.Name),
Label: "label",
Description: "description",
IsInternalExtension: true,
MediaLink: blobURL,
Eula: "eula-url",
PrivacyURI: "privacy-url",
HomepageURI: "homepage-url",
IsJSONExtension: true,
CompanyName: "company",
SupportedOS: "supported-os",
}
bs, err := xml.MarshalIndent(manifest, "", " ")
if err != nil {
log.Fatalf("xml marshall error: %v", err)
}
fmt.Println(string(bs))
}