initial commit
This commit is contained in:
commit
501d579a90
35 changed files with 11357 additions and 0 deletions
91
userdata.go
Normal file
91
userdata.go
Normal file
|
|
@ -0,0 +1,91 @@
|
|||
// Copyright (C) 2020 Marius Schellenberger
|
||||
|
||||
package pve
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"gopkg.in/yaml.v2"
|
||||
"net/url"
|
||||
)
|
||||
|
||||
func parseUserData(s string) (u *UserData, err error) {
|
||||
s, err = url.QueryUnescape(s)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
b, err := base64.StdEncoding.DecodeString(s)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
return UnmarshalUserData(b)
|
||||
}
|
||||
|
||||
func UnmarshalUserData(b []byte) (u *UserData, err error) {
|
||||
u = new(UserData)
|
||||
err = yaml.Unmarshal(b, u)
|
||||
return
|
||||
}
|
||||
func MarshalUserData(u *UserData) ([]byte, error) {
|
||||
return yaml.Marshal(u)
|
||||
}
|
||||
|
||||
type UserData struct {
|
||||
Hostname string `yaml:"hostname"`
|
||||
ManageEtcHosts bool `yaml:"manage_etc_hosts,omitempty"`
|
||||
SSHAuthorizedKeys []string `yaml:"ssh_authorized_keys,omitempty"`
|
||||
PackageUpdate bool `yaml:"package_update,omitempty"`
|
||||
PackageUpgrade bool `yaml:"package_upgrade,omitempty"`
|
||||
APT APTConfig `yaml:"apt,omitempty"`
|
||||
NTP NTP `yaml:"ntp,omitempty"`
|
||||
Users []User `yaml:"users,omitempty"`
|
||||
Packages [][]string `yaml:"packages,omitempty"`
|
||||
Runcmd []string `yaml:"runcmd,omitempty"`
|
||||
FinalMessage string `yaml:"final_message,omitempty"`
|
||||
WriteFiles []File `yaml:"write_files,omitempty"`
|
||||
}
|
||||
|
||||
func (u *UserData) String() (s string, err error) {
|
||||
b, err := MarshalUserData(u)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
s = base64.StdEncoding.EncodeToString(b)
|
||||
return
|
||||
}
|
||||
|
||||
type NTP struct {
|
||||
Servers []string `yaml:"servers,omitempty"`
|
||||
Enabled *bool `yaml:"enabled,omitempty"`
|
||||
}
|
||||
|
||||
type User struct {
|
||||
Name string `yaml:"name"`
|
||||
Gecos *string `yaml:"gecos,omitempty"`
|
||||
Groups *string `yaml:"groups,omitempty"`
|
||||
HomeDir *string `yaml:"homedir,omitempty"`
|
||||
Inactive *bool `yaml:"inactive,omitempty"`
|
||||
Shell *string `yaml:"shell,omitempty"`
|
||||
Passwd *string `yaml:"passwd,omitempty"`
|
||||
PrimaryGroup *string `yaml:"primary_group,omitempty"`
|
||||
LockPassword *bool `yaml:"lock_passwd,omitempty"`
|
||||
Sudo *string `yaml:"sudo,omitempty"`
|
||||
SSHAuthorizedKeys []string `yaml:"ssh_authorized_keys,omitempty"`
|
||||
}
|
||||
|
||||
type File struct {
|
||||
Content string `yaml:"content"`
|
||||
Path string `yaml:"path"`
|
||||
Owner string `yaml:"owner,omitempty"`
|
||||
Permissions string `yaml:"permissions,omitempty"`
|
||||
}
|
||||
|
||||
type APTConfig struct {
|
||||
Sources map[string]APTSource
|
||||
}
|
||||
|
||||
type APTSource struct {
|
||||
Arches string `yaml:"arches,omitempty"`
|
||||
Source string `yaml:"source"`
|
||||
Keyserver string `yaml:"keyserver"`
|
||||
Keyid string `yaml:"keyid"`
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue