1
// Copyright 2016 Canonical Ltd.
2
// Copyright 2016 Cloudbase Solutions SRL
3
// Licensed under the AGPLv3, see LICENCE file for details.
15
"github.com/juju/errors"
19
// Copyright {{.CopyrightYear}} Canonical Ltd.
20
// Copyright {{.CopyrightYear}} Cloudbase Solutions SRL
21
// Licensed under the AGPLv3, see LICENCE file for details.
25
// Generated code - do not edit.
27
const addJujuUser = {{.AddJujuUser}}
28
const windowsPowershellHelpers = {{.WindowsPowershellHelper}}
31
// compoundWinPowershellFunc returns the windows powershell helper
32
// functions declared under the windowsuserdatafiles/ dir
33
func compoundWinPowershellFuncs() (string, error) {
34
var winPowershellFunc bytes.Buffer
36
filenames := []string{
37
"windowsuserdatafiles/retry.ps1",
38
"windowsuserdatafiles/untar.ps1",
39
"windowsuserdatafiles/filesha256.ps1",
40
"windowsuserdatafiles/invokewebrequest.ps1",
42
for _, filename := range filenames {
43
content, err := ioutil.ReadFile(filename)
45
return "", errors.Trace(err)
47
winPowershellFunc.Write(content)
50
return winPowershellFunc.String(), nil
53
// CompoundJujuUser retuns the windows powershell funcs with c# bindings
54
// declared under the windowsuserdatafiles/ dir
55
func compoundJujuUser() (string, error) {
57
// note that addJujuUser.ps1 has hinting format locations for sprintf
58
// in that hinting locations we will add the c# scripts under the same file
59
content, err := ioutil.ReadFile("windowsuserdatafiles/addJujuUser.ps1")
61
return "", errors.Trace(err)
64
// take the two addJujuUser data c# scripts and construct the powershell
65
// script for adding user for juju in windows
66
cryptoAPICode, err := ioutil.ReadFile("windowsuserdatafiles/CryptoApi.cs")
68
return "", errors.Trace(err)
70
carbonCode, err := ioutil.ReadFile("windowsuserdatafiles/Carbon.cs")
72
return "", errors.Trace(err)
75
return fmt.Sprintf(string(content), string(cryptoAPICode), string(carbonCode)), nil
78
// This generator reads from a file and generates a Go file with the
79
// file's content assigned to a go constant.
82
fmt.Println("Usage: winuserdata <copyrightyear> <gofile> <pkgname>")
85
addJujuUser, err := compoundJujuUser()
90
winpowershell, err := compoundWinPowershellFuncs()
99
WindowsPowershellHelper string
104
t, err := template.New("").Parse(fileTemplate)
110
addJujuUser = fmt.Sprintf("\n%s", addJujuUser)
111
winpowershell = fmt.Sprintf("\n%s", winpowershell)
113
// Quote any ` in the data.
114
addJujuUser = strings.Replace(addJujuUser, "`", "` + \"`\" + `", -1)
115
winpowershell = strings.Replace(winpowershell, "`", "` + \"`\" + `", -1)
117
t.Execute(&buf, content{
118
AddJujuUser: fmt.Sprintf("`%s`", addJujuUser),
119
WindowsPowershellHelper: fmt.Sprintf("`%s`", winpowershell),
121
CopyrightYear: os.Args[1],
124
err = ioutil.WriteFile(os.Args[2], buf.Bytes(), 0644)