本文整理汇总了Golang中code/cloudfoundry/org/cli/plugin.CliConnection.AccessToken方法的典型用法代码示例。如果您正苦于以下问题:Golang CliConnection.AccessToken方法的具体用法?Golang CliConnection.AccessToken怎么用?Golang CliConnection.AccessToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类code/cloudfoundry/org/cli/plugin.CliConnection
的用法示例。
在下文中一共展示了CliConnection.AccessToken方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Run
func (c *Test1) Run(cliConnection plugin.CliConnection, args []string) {
if args[0] == "new-api" {
token, _ := cliConnection.AccessToken()
fmt.Println("Access Token:", token)
fmt.Println("")
app, err := cliConnection.GetApp("test_app")
fmt.Println("err for test_app", err)
fmt.Println("test_app is: ", app)
hasOrg, _ := cliConnection.HasOrganization()
fmt.Println("Has Organization Targeted:", hasOrg)
currentOrg, _ := cliConnection.GetCurrentOrg()
fmt.Println("Current Org:", currentOrg)
org, _ := cliConnection.GetOrg(currentOrg.Name)
fmt.Println(currentOrg.Name, " Org:", org)
orgs, _ := cliConnection.GetOrgs()
fmt.Println("Orgs:", orgs)
hasSpace, _ := cliConnection.HasSpace()
fmt.Println("Has Space Targeted:", hasSpace)
currentSpace, _ := cliConnection.GetCurrentSpace()
fmt.Println("Current space:", currentSpace)
space, _ := cliConnection.GetSpace(currentSpace.Name)
fmt.Println("Space:", space)
spaces, _ := cliConnection.GetSpaces()
fmt.Println("Spaces:", spaces)
loggregator, _ := cliConnection.LoggregatorEndpoint()
fmt.Println("Loggregator Endpoint:", loggregator)
dopplerEndpoint, _ := cliConnection.DopplerEndpoint()
fmt.Println("Doppler Endpoint:", dopplerEndpoint)
user, _ := cliConnection.Username()
fmt.Println("Current user:", user)
userGUID, _ := cliConnection.UserGuid()
fmt.Println("Current user guid:", userGUID)
email, _ := cliConnection.UserEmail()
fmt.Println("Current user email:", email)
hasAPI, _ := cliConnection.HasAPIEndpoint()
fmt.Println("Has API Endpoint:", hasAPI)
api, _ := cliConnection.ApiEndpoint()
fmt.Println("Current api:", api)
version, _ := cliConnection.ApiVersion()
fmt.Println("Current api version:", version)
loggedIn, _ := cliConnection.IsLoggedIn()
fmt.Println("Is Logged In:", loggedIn)
isSSLDisabled, _ := cliConnection.IsSSLDisabled()
fmt.Println("Is SSL Disabled:", isSSLDisabled)
} else if args[0] == "test_1_cmd1" {
theFirstCmd()
} else if args[0] == "test_1_cmd2" {
theSecondCmd()
} else if args[0] == "CLI-MESSAGE-UNINSTALL" {
uninstalling()
}
}
示例2: Logs
func Logs(cliConnection plugin.CliConnection, args []string) {
appName := args[1]
rawOutput, _ := cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/apps?names=%s", appName))
apps := V3AppsModel{}
output := strings.Join(rawOutput, "")
json.Unmarshal([]byte(output), &apps)
if len(apps.Apps) == 0 {
fmt.Printf("App %s not found\n", appName)
return
}
app := apps.Apps[0]
messageQueue := logs.NewNoaaMessageQueue()
bufferTime := 25 * time.Millisecond
ticker := time.NewTicker(bufferTime)
logChan := make(chan logs.Loggable)
errChan := make(chan error)
dopplerEndpoint, err := cliConnection.DopplerEndpoint()
FreakOut(err)
ssl, err := cliConnection.IsSSLDisabled()
FreakOut(err)
tlsConfig := net.NewTLSConfig([]tls.Certificate{}, ssl)
noaaConsumer := consumer.New(dopplerEndpoint, tlsConfig, http.ProxyFromEnvironment)
defer func() {
noaaConsumer.Close()
flushMessages(logChan, messageQueue)
}()
onConnect := func() {
fmt.Printf("Tailing logs for app %s...\r\n\r\n", appName)
}
noaaConsumer.SetOnConnectCallback(onConnect)
accessToken, err := cliConnection.AccessToken()
FreakOut(err)
c, e := noaaConsumer.TailingLogs(app.Guid, accessToken)
go func() {
for {
select {
case msg, ok := <-c:
if !ok {
ticker.Stop()
flushMessages(logChan, messageQueue)
close(logChan)
close(errChan)
return
}
messageQueue.PushMessage(msg)
case err := <-e:
if err != nil {
errChan <- err
ticker.Stop()
close(logChan)
close(errChan)
return
}
}
}
}()
go func() {
for range ticker.C {
flushMessages(logChan, messageQueue)
}
}()
for {
select {
case msg := <-logChan:
fmt.Printf("%s\r\n", logMessageOutput(msg, time.Local))
case err, ok := <-errChan:
if !ok {
FreakOut(err)
}
}
}
}
示例3: Push
func Push(cliConnection plugin.CliConnection, args []string) {
appDir := "."
buildpack := "null"
dockerImage := ""
fc := flags.New()
fc.NewStringFlag("filepath", "p", "path to app dir or zip to upload")
fc.NewStringFlag("buildpack", "b", "the buildpack to use")
fc.NewStringFlag("docker-image", "di", "the docker image to use")
fc.Parse(args...)
if fc.IsSet("p") {
appDir = fc.String("p")
}
if fc.IsSet("b") {
buildpack = fmt.Sprintf(`"%s"`, fc.String("b"))
}
if fc.IsSet("di") {
dockerImage = fmt.Sprintf(`"%s"`, fc.String("di"))
}
mySpace, _ := cliConnection.GetCurrentSpace()
lifecycle := ""
if dockerImage != "" {
lifecycle = `"lifecycle": { "type": "docker", "data": {} }`
} else {
lifecycle = fmt.Sprintf(`"lifecycle": { "type": "buildpack", "data": { "buildpack": %s } }`, buildpack)
}
//create the app
rawOutput, err := cliConnection.CliCommandWithoutTerminalOutput("curl", "/v3/apps", "-X", "POST", "-d",
fmt.Sprintf(`{"name":"%s", "relationships": { "space": {"guid":"%s"}}, %s}`, fc.Args()[1], mySpace.Guid, lifecycle))
FreakOut(err)
output := strings.Join(rawOutput, "")
app := V3AppModel{}
err = json.Unmarshal([]byte(output), &app)
FreakOut(err)
if app.Error_Code != "" {
FreakOut(errors.New("Error creating v3 app: " + app.Error_Code))
}
time.Sleep(2 * time.Second) // wait for app to settle before kicking off the log streamer
go Logs(cliConnection, args)
time.Sleep(2 * time.Second) // b/c sharing the cliConnection makes things break
//create package
pack := V3PackageModel{}
if dockerImage != "" {
request := fmt.Sprintf(`{"type": "docker", "data": {"image": %s}}`, dockerImage)
rawOutput, err = cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/apps/%s/packages", app.Guid), "-X", "POST", "-d", request)
FreakOut(err)
output = strings.Join(rawOutput, "")
err = json.Unmarshal([]byte(output), &pack)
if err != nil {
FreakOut(errors.New("Error creating v3 app package: " + app.Error_Code))
}
} else {
//create the empty package to upload the app bits to
rawOutput, err = cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/apps/%s/packages", app.Guid), "-X", "POST", "-d", "{\"type\": \"bits\"}")
FreakOut(err)
output = strings.Join(rawOutput, "")
err = json.Unmarshal([]byte(output), &pack)
if err != nil {
FreakOut(errors.New("Error creating v3 app package: " + app.Error_Code))
}
token, err := cliConnection.AccessToken()
FreakOut(err)
api, apiErr := cliConnection.ApiEndpoint()
FreakOut(apiErr)
apiString := fmt.Sprintf("%s", api)
if strings.Index(apiString, "s") == 4 {
apiString = apiString[:4] + apiString[5:]
}
//gather files
zipper := appfiles.ApplicationZipper{}
fileutils.TempFile("uploads", func(zipFile *os.File, err error) {
zipper.Zip(appDir, zipFile)
_, upload := exec.Command("curl", fmt.Sprintf("%s/v3/packages/%s/upload", apiString, pack.Guid), "-F", fmt.Sprintf("[email protected]%s", zipFile.Name()), "-H", fmt.Sprintf("Authorization: %s", token), "-H", "Expect:").Output()
FreakOut(upload)
})
//waiting for cc to pour bits into blobstore
Poll(cliConnection, fmt.Sprintf("/v3/packages/%s", pack.Guid), "READY", 5*time.Minute, "Package failed to upload")
}
rawOutput, err = cliConnection.CliCommandWithoutTerminalOutput("curl", fmt.Sprintf("/v3/packages/%s/droplets", pack.Guid), "-X", "POST", "-d", "{}")
FreakOut(err)
output = strings.Join(rawOutput, "")
droplet := V3DropletModel{}
err = json.Unmarshal([]byte(output), &droplet)
if err != nil {
FreakOut(errors.New("error marshaling the v3 droplet: " + err.Error()))
}
//wait for the droplet to be ready
Poll(cliConnection, fmt.Sprintf("/v3/droplets/%s", droplet.Guid), "STAGED", 10*time.Minute, "Droplet failed to stage")
//assign droplet to the app
//.........这里部分代码省略.........