本文整理汇总了Golang中github.com/deis/deis/client/controller/client.New函数的典型用法代码示例。如果您正苦于以下问题:Golang New函数的具体用法?Golang New怎么用?Golang New使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了New函数的19个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
}
开发者ID:robeferre,项目名称:deis,代码行数:60,代码来源:auth.go
示例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
}
开发者ID:ngpestelos,项目名称:deis,代码行数:36,代码来源:apps.go
示例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
}
开发者ID:smt116,项目名称:deis,代码行数:27,代码来源:keys.go
示例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
}
开发者ID:smt116,项目名称:deis,代码行数:27,代码来源:users.go
示例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
}
开发者ID:smt116,项目名称:deis,代码行数:26,代码来源:apps.go
示例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
}
开发者ID:CodeJuan,项目名称:deis,代码行数:30,代码来源:keys.go
示例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
}
开发者ID:robeferre,项目名称:deis,代码行数:27,代码来源:auth.go
示例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
}
开发者ID:CodeJuan,项目名称:deis,代码行数:59,代码来源:certs.go
示例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
}
开发者ID:robeferre,项目名称:deis,代码行数:11,代码来源:auth.go
示例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
}
开发者ID:naveenholla,项目名称:deis,代码行数:49,代码来源:apps.go
示例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
}
开发者ID:CodeJuan,项目名称:deis,代码行数:18,代码来源:keys.go
示例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
}
开发者ID:CodeJuan,项目名称:deis,代码行数:17,代码来源:perms.go
示例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
}
开发者ID:CodeJuan,项目名称:deis,代码行数:17,代码来源:utils.go
示例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
}
开发者ID:robeferre,项目名称:deis,代码行数:45,代码来源:auth.go
示例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
}
开发者ID:smt116,项目名称:deis,代码行数:45,代码来源:apps.go
示例16: CertAdd
// CertAdd adds a cert to the controller.
func CertAdd(cert, key, commonName, sans string) error {
c, err := client.New()
if err != nil {
return err
}
fmt.Print("Adding SSL endpoint... ")
quit := progress()
err = processCertsAdd(c, cert, key, commonName, sans)
quit <- true
<-quit
if err != nil {
return err
}
fmt.Println("done")
return nil
}
开发者ID:CodeJuan,项目名称:deis,代码行数:21,代码来源:certs.go
示例17: CertRemove
// CertRemove deletes a cert from the controller.
func CertRemove(commonName string) error {
c, err := client.New()
if err != nil {
return err
}
fmt.Printf("Removing %s... ", commonName)
quit := progress()
certs.Delete(c, commonName)
quit <- true
<-quit
if err == nil {
fmt.Println("done")
}
return err
}
开发者ID:CodeJuan,项目名称:deis,代码行数:22,代码来源:certs.go
示例18: 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.Fprintln(os.Stderr, "Account not changed")
return nil
}
err = auth.Delete(c, username)
cleanup := fmt.Errorf("\n%s %s\n\n", "409", "Conflict")
if reflect.DeepEqual(err, cleanup) {
fmt.Printf("%s still has application associated with it. Transfer ownership or delete them first\n", username)
return nil
} else 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
}
开发者ID:CodeJuan,项目名称:deis,代码行数:64,代码来源:auth.go
示例19: Register
// Register creates a account on a Deis controller.
func Register(controller string, username string, password string, email string,
sslVerify bool) error {
u, err := url.Parse(controller)
httpClient := client.CreateHTTPClient(sslVerify)
if err != nil {
return err
}
controllerURL, err := chooseScheme(*u)
if err != nil {
return err
}
if err = client.CheckConnection(httpClient, controllerURL); err != nil {
return err
}
if username == "" {
fmt.Print("username: ")
fmt.Scanln(&username)
}
if password == "" {
fmt.Print("password: ")
password, err = readPassword()
fmt.Printf("\npassword (confirm): ")
passwordConfirm, err := readPassword()
fmt.Println()
if err != nil {
return err
}
if password != passwordConfirm {
return errors.New("Password mismatch, aborting registration.")
}
}
if email == "" {
fmt.Print("email: ")
fmt.Scanln(&email)
}
c := &client.Client{ControllerURL: controllerURL, SSLVerify: sslVerify, HTTPClient: httpClient}
tempClient, err := client.New()
if err == nil {
c.Token = tempClient.Token
}
err = auth.Register(c, username, password, email)
c.Token = ""
if err != nil {
fmt.Print("Registration failed: ")
return err
}
fmt.Printf("Registered %s\n", username)
return doLogin(c, username, password)
}
开发者ID:robeferre,项目名称:deis,代码行数:67,代码来源:auth.go
注:本文中的github.com/deis/deis/client/controller/client.New函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论