本文整理匯總了Golang中github.com/cloudfoundry/cli/cf/configuration/core_config.Repository.SetAccessToken方法的典型用法代碼示例。如果您正苦於以下問題:Golang Repository.SetAccessToken方法的具體用法?Golang Repository.SetAccessToken怎麽用?Golang Repository.SetAccessToken使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類github.com/cloudfoundry/cli/cf/configuration/core_config.Repository
的用法示例。
在下文中一共展示了Repository.SetAccessToken方法的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1:
deps.RepoLocator = deps.RepoLocator.SetUserRepository(userRepo)
command_registry.Commands.SetCommand(command_registry.Commands.FindCommand("delete-user").SetDependency(deps, pluginCall))
}
BeforeEach(func() {
ui = &testterm.FakeUI{Inputs: []string{"y"}}
userRepo = &testapi.FakeUserRepository{}
requirementsFactory = &testreq.FakeReqFactory{LoginSuccess: true}
configRepo = testconfig.NewRepositoryWithDefaults()
token, err := testconfig.EncodeAccessToken(core_config.TokenInfo{
UserGuid: "admin-user-guid",
Username: "admin-user",
})
Expect(err).ToNot(HaveOccurred())
configRepo.SetAccessToken(token)
})
runCommand := func(args ...string) bool {
return testcmd.RunCliCommand("delete-user", args, requirementsFactory, updateCommandDependency, false)
}
Describe("requirements", func() {
It("fails when not logged in", func() {
requirementsFactory.LoginSuccess = false
Expect(runCommand("my-user")).To(BeFalse())
})
It("fails with usage when no arguments are given", func() {
runCommand()
示例2:
Expect(err).ToNot(HaveOccurred())
Expect(result).To(BeTrue())
})
})
Context(".IsLoggedIn", func() {
BeforeEach(func() {
rpcService, err = NewRpcService(nil, nil, nil, config)
err := rpcService.Start()
Expect(err).ToNot(HaveOccurred())
pingCli(rpcService.Port())
})
It("returns the IsLoggedIn setting in config", func() {
config.SetAccessToken("Logged-In-Token")
client, err = rpc.Dial("tcp", "127.0.0.1:"+rpcService.Port())
Expect(err).ToNot(HaveOccurred())
var result bool
err = client.Call("CliRpcCmd.IsLoggedIn", "", &result)
Expect(err).ToNot(HaveOccurred())
Expect(result).To(BeTrue())
})
})
Context(".HasOrganization and .HasSpace ", func() {
BeforeEach(func() {
rpcService, err = NewRpcService(nil, nil, nil, config)
err := rpcService.Start()
Expect(err).ToNot(HaveOccurred())
示例3:
))
})
Describe("when there is no api endpoint set", func() {
BeforeEach(func() {
requirementsFactory.ApiEndpointSuccess = false
})
It("fails requirements", func() {
Expect(callTarget([]string{})).To(BeFalse())
})
})
Describe("when the user is not logged in", func() {
BeforeEach(func() {
config.SetAccessToken("")
})
It("prints the target info when no org or space is specified", func() {
Expect(callTarget([]string{})).To(BeTrue())
Expect(ui.ShowConfigurationCalled).To(BeTrue())
})
It("panics silently so that it returns an exit code of 1", func() {
callTarget([]string{})
Expect(ui.PanickedQuietly).To(BeTrue())
})
It("fails requirements when targeting a space or org", func() {
Expect(callTarget([]string{"-o", "some-crazy-org-im-not-in"})).To(BeFalse())
示例4:
{
"account_number": "the-account-number",
"username": "the-username",
"password": "the-password-3",
},
}))
Expect(ui.Outputs).To(ContainSubstrings([]string{"FAILED"}))
})
})
})
Describe("updates to the config", func() {
BeforeEach(func() {
Config.SetApiEndpoint("api.the-old-endpoint.com")
Config.SetAccessToken("the-old-access-token")
Config.SetRefreshToken("the-old-refresh-token")
})
JustBeforeEach(func() {
testcmd.RunCliCommand("login", Flags, nil, updateCommandDependency, false)
})
var ItShowsTheTarget = func() {
It("shows the target", func() {
Expect(ui.ShowConfigurationCalled).To(BeTrue())
})
}
var ItDoesntShowTheTarget = func() {
It("does not show the target info", func() {
示例5:
config.SetApiVersion("3")
Expect(config.ApiVersion()).To(Equal("3"))
config.SetAuthenticationEndpoint("http://auth.the-endpoint")
Expect(config.AuthenticationEndpoint()).To(Equal("http://auth.the-endpoint"))
config.SetLoggregatorEndpoint("http://loggregator.the-endpoint")
Expect(config.LoggregatorEndpoint()).To(Equal("http://loggregator.the-endpoint"))
config.SetDopplerEndpoint("http://doppler.the-endpoint")
Expect(config.DopplerEndpoint()).To(Equal("http://doppler.the-endpoint"))
config.SetUaaEndpoint("http://uaa.the-endpoint")
Expect(config.UaaEndpoint()).To(Equal("http://uaa.the-endpoint"))
config.SetAccessToken("the-token")
Expect(config.AccessToken()).To(Equal("the-token"))
config.SetSSHOAuthClient("oauth-client-id")
Expect(config.SSHOAuthClient()).To(Equal("oauth-client-id"))
config.SetRefreshToken("the-token")
Expect(config.RefreshToken()).To(Equal("the-token"))
organization := maker.NewOrgFields(maker.Overrides{"name": "the-org"})
config.SetOrganizationFields(organization)
Expect(config.OrganizationFields()).To(Equal(organization))
space := maker.NewSpaceFields(maker.Overrides{"name": "the-space"})
config.SetSpaceFields(space)
Expect(config.SpaceFields()).To(Equal(space))
示例6:
)
updateCommandDependency := func(pluginCall bool) {
deps.Ui = ui
deps.Config = config
deps.RepoLocator = deps.RepoLocator.SetAuthenticationRepository(authRepo)
command_registry.Commands.SetCommand(command_registry.Commands.FindCommand("auth").SetDependency(deps, pluginCall))
}
BeforeEach(func() {
ui = &testterm.FakeUI{}
config = testconfig.NewRepositoryWithDefaults()
requirementsFactory = &testreq.FakeReqFactory{}
authRepo = &authenticationfakes.FakeAuthenticationRepository{}
authRepo.AuthenticateStub = func(credentials map[string]string) error {
config.SetAccessToken("my-access-token")
config.SetRefreshToken("my-refresh-token")
return nil
}
deps = command_registry.NewDependency()
})
Describe("requirements", func() {
It("fails with usage when given too few arguments", func() {
testcmd.RunCliCommand("auth", []string{}, requirementsFactory, updateCommandDependency, false)
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"Incorrect Usage", "Requires", "arguments"},
))
})
示例7:
testterm "github.com/cloudfoundry/cli/testhelpers/terminal"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("logout command", func() {
var config core_config.Repository
BeforeEach(func() {
org := models.OrganizationFields{}
org.Name = "MyOrg"
space := models.SpaceFields{}
space.Name = "MySpace"
config = testconfig.NewRepository()
config.SetAccessToken("MyAccessToken")
config.SetOrganizationFields(org)
config.SetSpaceFields(space)
ui := new(testterm.FakeUI)
l := commands.NewLogout(ui, config)
l.Run(nil)
})
It("clears access token from the config", func() {
Expect(config.AccessToken()).To(Equal(""))
})
It("clears organization fields from the config", func() {
Expect(config.OrganizationFields()).To(Equal(models.OrganizationFields{}))
})
示例8:
requirementsFactory *testreq.FakeReqFactory
ui *testterm.FakeUI
userRepo *testapi.FakeUserRepository
config core_config.Repository
deps command_registry.Dependency
)
BeforeEach(func() {
requirementsFactory = &testreq.FakeReqFactory{LoginSuccess: true}
ui = new(testterm.FakeUI)
userRepo = &testapi.FakeUserRepository{}
config = testconfig.NewRepositoryWithDefaults()
accessToken, _ := testconfig.EncodeAccessToken(core_config.TokenInfo{
Username: "current-user",
})
config.SetAccessToken(accessToken)
})
updateCommandDependency := func(pluginCall bool) {
deps.Ui = ui
deps.Config = config
deps.RepoLocator = deps.RepoLocator.SetUserRepository(userRepo)
command_registry.Commands.SetCommand(command_registry.Commands.FindCommand("create-user").SetDependency(deps, pluginCall))
}
runCommand := func(args ...string) bool {
return testcmd.RunCliCommand("create-user", args, requirementsFactory, updateCommandDependency, false)
}
It("creates a user", func() {
runCommand("my-user", "my-password")
示例9:
keepGoing = cb(s)
if !keepGoing {
return nil
}
}
return nil
}
}
BeforeEach(func() {
Flags = []string{}
Config = testconfig.NewRepository()
ui = &testterm.FakeUI{}
authRepo = &authenticationfakes.FakeAuthenticationRepository{}
authRepo.AuthenticateStub = func(credentials map[string]string) error {
Config.SetAccessToken("my_access_token")
Config.SetRefreshToken("my_refresh_token")
return nil
}
endpointRepo = &testapi.FakeEndpointRepository{}
org = models.Organization{}
org.Name = "my-new-org"
org.Guid = "my-new-org-guid"
orgRepo = &fake_organizations.FakeOrganizationRepository{}
orgRepo.ListOrgsReturns([]models.Organization{org}, nil)
space := models.Space{}
space.Guid = "my-space-guid"
space.Name = "my-space"
示例10:
Expect(err).ToNot(HaveOccurred())
Expect(result).To(BeTrue())
})
})
Context(".IsLoggedIn", func() {
BeforeEach(func() {
rpcService, err = NewRpcService(nil, nil, config, api.RepositoryLocator{}, nil)
err := rpcService.Start()
Expect(err).ToNot(HaveOccurred())
pingCli(rpcService.Port())
})
It("returns the IsLoggedIn setting in config", func() {
config.SetAccessToken("Logged-In-Token")
client, err = rpc.Dial("tcp", "127.0.0.1:"+rpcService.Port())
Expect(err).ToNot(HaveOccurred())
var result bool
err = client.Call("CliRpcCmd.IsLoggedIn", "", &result)
Expect(err).ToNot(HaveOccurred())
Expect(result).To(BeTrue())
})
})
Context(".HasOrganization and .HasSpace ", func() {
BeforeEach(func() {
rpcService, err = NewRpcService(nil, nil, config, api.RepositoryLocator{}, nil)
err := rpcService.Start()
Expect(err).ToNot(HaveOccurred())