本文整理汇总了Golang中github.com/deis/deis/client/controller/client.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Cancel
// Cancel deletes a user's account.
func Cancel(username string, password string, yes bool) error {
c, err := client.New()
if err != nil {
return err
}
if username == "" || password != "" {
fmt.Println("Please log in again in order to cancel this account")
if err = Login(c.ControllerURL.String(), username, password, c.SSLVerify); err != nil {
return err
}
}
if yes == false {
confirm := ""
c, err = client.New()
if err != nil {
return err
}
deletedUser := username
if deletedUser == "" {
deletedUser = c.Username
}
fmt.Printf("cancel account %s at %s? (y/N): ", deletedUser, c.ControllerURL.String())
fmt.Scanln(&confirm)
if strings.ToLower(confirm) == "y" {
yes = true
}
}
if yes == false {
fmt.Println("Account not changed")
return nil
}
err = auth.Delete(c, username)
if err != nil {
return err
}
// If user targets themselves, logout.
if username != "" || c.Username == username {
if err := client.Delete(); err != nil {
return err
}
}
fmt.Println("Account cancelled")
return nil
}
示例2: AppCreate
// AppCreate creates an app.
func AppCreate(id string, buildpack string, remote string, noRemote bool) error {
c, err := client.New()
fmt.Print("Creating Application... ")
quit := progress()
app, err := apps.New(c, id)
quit <- true
<-quit
if err != nil {
return err
}
fmt.Printf("done, created %s\n", app.ID)
if buildpack != "" {
configValues := api.Config{
Values: map[string]interface{}{
"BUILDPACK_URL": buildpack,
},
}
if _, err = config.Set(c, app.ID, configValues); err != nil {
return err
}
}
if !noRemote {
return git.CreateRemote(c.ControllerURL.Host, remote, app.ID)
}
fmt.Println("remote available at", git.RemoteURL(c.ControllerURL.Host, app.ID))
return nil
}
示例3: KeysList
// KeysList lists a user's keys.
func KeysList(results int) error {
c, err := client.New()
if err != nil {
return err
}
if results == defaultLimit {
results = c.ResponseLimit
}
keys, count, err := keys.List(c, results)
if err != nil {
return err
}
fmt.Printf("=== %s Keys%s", c.Username, limitCount(len(keys), count))
sort.Sort(keys)
for _, key := range keys {
fmt.Printf("%s %s...%s\n", key.ID, key.Public[:16], key.Public[len(key.Public)-10:])
}
return nil
}
示例4: UsersList
// UsersList lists users registered with the controller.
func UsersList(results int) error {
c, err := client.New()
if err != nil {
return err
}
if results == defaultLimit {
results = c.ResponseLimit
}
users, count, err := users.List(c, results)
if err != nil {
return err
}
fmt.Printf("=== Users%s", limitCount(len(users), count))
sort.Sort(users)
for _, user := range users {
fmt.Println(user.Username)
}
return nil
}
示例5: AppsList
// AppsList lists apps on the Deis controller.
func AppsList(results int) error {
c, err := client.New()
if err != nil {
return err
}
if results == defaultLimit {
results = c.ResponseLimit
}
apps, count, err := apps.List(c, results)
if err != nil {
return err
}
fmt.Printf("=== Apps%s", limitCount(len(apps), count))
sort.Sort(apps)
for _, app := range apps {
fmt.Println(app.ID)
}
return nil
}
示例6: KeyAdd
// KeyAdd adds keys.
func KeyAdd(keyLocation string) error {
c, err := client.New()
if err != nil {
return err
}
var key api.KeyCreateRequest
if keyLocation == "" {
key, err = chooseKey()
} else {
key, err = getKey(keyLocation)
}
if err != nil {
return err
}
fmt.Printf("Uploading %s to deis...", path.Base(key.Name))
if _, err = keys.New(c, key.ID, key.Public); err != nil {
fmt.Println()
return err
}
fmt.Println(" done")
return nil
}
示例7: Regenerate
// Regenerate regenenerates a user's token.
func Regenerate(username string, all bool) error {
c, err := client.New()
if err != nil {
return err
}
token, err := auth.Regenerate(c, username, all)
if err != nil {
return err
}
if username == "" && all == false {
c.Token = token
err = c.Save()
if err != nil {
return err
}
}
fmt.Println("Token Regenerated")
return nil
}
示例8: CertsList
// CertsList lists certs registered with the controller.
func CertsList(results int) error {
c, err := client.New()
if err != nil {
return err
}
if results == defaultLimit {
results = c.ResponseLimit
}
certList, _, err := certs.List(c, results)
if err != nil {
return err
}
if len(certList) == 0 {
fmt.Println("No certs")
return nil
}
certMap := make(map[string]string)
nameMax := 0
expiresMax := 0
for _, cert := range certList {
certMap[cert.Name] = cert.Expires
if len(cert.Name) > nameMax {
nameMax = len(cert.Name)
}
if len(cert.Expires) > nameMax {
expiresMax = len(cert.Expires)
}
}
nameHeader := "Common Name"
expiresHeader := "Expires"
tabSpaces := 5
bufferSpaces := tabSpaces
if nameMax < len(nameHeader) {
tabSpaces += len(nameHeader) - nameMax
nameMax = len(nameHeader)
} else {
bufferSpaces += nameMax - len(nameHeader)
}
if expiresMax < len(expiresHeader) {
expiresMax = len(expiresHeader)
}
fmt.Printf("%s%s%s\n", nameHeader, strings.Repeat(" ", bufferSpaces), expiresHeader)
fmt.Printf("%s%s%s\n", strings.Repeat("-", nameMax), strings.Repeat(" ", 5),
strings.Repeat("-", expiresMax))
fmt.Print(prettyprint.PrettyTabs(certMap, tabSpaces))
return nil
}
示例9: Whoami
// Whoami prints the logged in user.
func Whoami() error {
c, err := client.New()
if err != nil {
return err
}
fmt.Printf("You are %s at %s\n", c.Username, c.ControllerURL.String())
return nil
}
示例10: AppDestroy
// AppDestroy destroys an app.
func AppDestroy(appID, confirm string) error {
gitSession := false
c, err := client.New()
if err != nil {
return err
}
if appID == "" {
appID, err = git.DetectAppName(c.ControllerURL.Host)
if err != nil {
return err
}
gitSession = true
}
if confirm == "" {
fmt.Printf(` ! WARNING: Potentially Destructive Action
! This command will destroy the application: %s
! To proceed, type "%s" or re-run this command with --confirm=%s
> `, appID, appID, appID)
fmt.Scanln(&confirm)
}
if confirm != appID {
return fmt.Errorf("App %s does not match confirm %s, aborting.", appID, confirm)
}
startTime := time.Now()
fmt.Printf("Destroying %s...\n", appID)
if err = apps.Delete(c, appID); err != nil {
return err
}
fmt.Printf("done in %ds\n", int(time.Since(startTime).Seconds()))
if gitSession {
return git.DeleteRemote(appID)
}
return nil
}
示例11: KeyRemove
// KeyRemove removes keys.
func KeyRemove(keyID string) error {
c, err := client.New()
if err != nil {
return err
}
fmt.Printf("Removing %s SSH Key...", keyID)
if err = keys.Delete(c, keyID); err != nil {
fmt.Println()
return err
}
fmt.Println(" done")
return nil
}
示例12: permsLoad
func permsLoad(appID string, admin bool) (*client.Client, string, error) {
c, err := client.New()
if err != nil {
return nil, "", err
}
if !admin && appID == "" {
appID, err = git.DetectAppName(c.ControllerURL.Host)
if err != nil {
return nil, "", err
}
}
return c, appID, err
}
示例13: load
func load(appID string) (*client.Client, string, error) {
c, err := client.New()
if err != nil {
return nil, "", err
}
if appID == "" {
appID, err = git.DetectAppName(c.ControllerURL.Host)
if err != nil {
return nil, "", err
}
}
return c, appID, nil
}
示例14: Passwd
// Passwd changes a user's password.
func Passwd(username string, password string, newPassword string) error {
c, err := client.New()
if err != nil {
return err
}
if password == "" && username == "" {
fmt.Print("current password: ")
password, err = readPassword()
fmt.Println()
if err != nil {
return err
}
}
if newPassword == "" {
fmt.Print("new password: ")
newPassword, err = readPassword()
fmt.Printf("\nnew password (confirm): ")
passwordConfirm, err := readPassword()
fmt.Println()
if err != nil {
return err
}
if newPassword != passwordConfirm {
return errors.New("Password mismatch, not changing.")
}
}
err = auth.Passwd(c, username, password, newPassword)
if err != nil {
fmt.Print("Password change failed: ")
return err
}
fmt.Println("Password change succeeded.")
return nil
}
示例15: AppCreate
// AppCreate creates an app.
func AppCreate(id string, buildpack string, remote string, noRemote bool) error {
c, err := client.New()
if err != nil {
return err
}
fmt.Print("Creating Application... ")
quit := progress()
app, err := apps.New(c, id)
quit <- true
<-quit
if err != nil {
return err
}
fmt.Printf("done, created %s\n", app.ID)
if buildpack != "" {
configValues := api.Config{
Values: map[string]interface{}{
"BUILDPACK_URL": buildpack,
},
}
if _, err = config.Set(c, app.ID, configValues); err != nil {
return err
}
}
if !noRemote {
if err = git.CreateRemote(c.ControllerURL.Host, remote, app.ID); err != nil {
if err.Error() == "exit status 128" {
fmt.Println("To replace the existing git remote entry, run:")
fmt.Printf(" git remote rename deis deis.old && deis git:remote -a %s\n", app.ID)
}
return err
}
}
fmt.Println("remote available at", git.RemoteURL(c.ControllerURL.Host, app.ID))
return nil
}