本文整理汇总了Golang中github.com/cloudfoundry/cli/cf/configuration/core_config.ReadWriter.SetAccessToken方法的典型用法代码示例。如果您正苦于以下问题:Golang ReadWriter.SetAccessToken方法的具体用法?Golang ReadWriter.SetAccessToken怎么用?Golang ReadWriter.SetAccessToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cloudfoundry/cli/cf/configuration/core_config.ReadWriter
的用法示例。
在下文中一共展示了ReadWriter.SetAccessToken方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1:
. "github.com/cloudfoundry/cli/cf/api"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Service Keys Repo", func() {
var (
ccServer *ghttp.Server
configRepo core_config.ReadWriter
repo ServiceKeyRepository
)
BeforeEach(func() {
configRepo = testconfig.NewRepositoryWithDefaults()
configRepo.SetAccessToken("BEARER my_access_token")
ccServer = ghttp.NewServer()
configRepo.SetApiEndpoint(ccServer.URL())
gateway := net.NewCloudControllerGateway(configRepo, time.Now, &testterm.FakeUI{})
repo = NewCloudControllerServiceKeyRepository(configRepo, gateway)
})
AfterEach(func() {
ccServer.Close()
})
Describe("CreateServiceKey", func() {
It("tries to create the service key", func() {
ccServer.AppendHandlers(
示例2:
)
var _ = Describe("logs with noaa repository", func() {
var (
fakeNoaaConsumer *testapi.FakeNoaaConsumer
config core_config.ReadWriter
fakeTokenRefresher *testapi.FakeAuthenticationRepository
repo api.LogsNoaaRepository
)
BeforeEach(func() {
fakeNoaaConsumer = &testapi.FakeNoaaConsumer{}
config = testconfig.NewRepositoryWithDefaults()
config.SetLoggregatorEndpoint("loggregator.test.com")
config.SetDopplerEndpoint("doppler.test.com")
config.SetAccessToken("the-access-token")
fakeTokenRefresher = &testapi.FakeAuthenticationRepository{}
repo = api.NewLogsNoaaRepository(config, fakeNoaaConsumer, fakeTokenRefresher)
})
Describe("RecentLogsFor", func() {
It("refreshes token and get metric once more if token has expired.", func() {
fakeNoaaConsumer.RecentLogsReturns([]*events.LogMessage{},
noaa_errors.NewUnauthorizedError("Unauthorized token"))
repo.RecentLogsFor("app-guid")
Ω(fakeTokenRefresher.RefreshTokenCalled).To(BeTrue())
Ω(fakeNoaaConsumer.RecentLogsCallCount()).To(Equal(2))
})
示例3:
Expect(config.AccessToken()).To(Equal(""))
Expect(config.AuthenticationEndpoint()).To(Equal("https://login.example.com"))
Expect(config.LoggregatorEndpoint()).To(Equal("wss://loggregator.foo.example.org:4443"))
Expect(config.DopplerEndpoint()).To(Equal("wss://doppler.foo.example.org:4443"))
Expect(config.ApiEndpoint()).To(Equal(testServer.URL))
Expect(config.ApiVersion()).To(Equal("42.0.0"))
Expect(config.HasOrganization()).To(BeFalse())
Expect(config.HasSpace()).To(BeFalse())
Expect(config.MinCliVersion()).To(Equal("6.5.0"))
Expect(config.MinRecommendedCliVersion()).To(Equal("6.7.0"))
})
Context("when the api endpoint does not change", func() {
BeforeEach(func() {
config.SetApiEndpoint(testServer.URL)
config.SetAccessToken("some access token")
config.SetRefreshToken("some refresh token")
})
It("does not clear the session if the api endpoint does not change", func() {
repo.UpdateEndpoint(testServer.URL)
Expect(config.OrganizationFields()).To(Equal(org))
Expect(config.SpaceFields()).To(Equal(space))
Expect(config.AccessToken()).To(Equal("some access token"))
Expect(config.RefreshToken()).To(Equal("some refresh token"))
})
})
})
Context("when the API request fails", func() {
示例4:
var (
requirementsFactory *testreq.FakeReqFactory
ui *testterm.FakeUI
userRepo *testapi.FakeUserRepository
configRepo core_config.ReadWriter
)
BeforeEach(func() {
requirementsFactory = &testreq.FakeReqFactory{LoginSuccess: true}
ui = new(testterm.FakeUI)
userRepo = &testapi.FakeUserRepository{}
configRepo = testconfig.NewRepositoryWithDefaults()
accessToken, _ := testconfig.EncodeAccessToken(core_config.TokenInfo{
Username: "current-user",
})
configRepo.SetAccessToken(accessToken)
})
runCommand := func(args ...string) bool {
cmd := NewCreateUser(ui, configRepo, userRepo)
return testcmd.RunCommand(cmd, args, requirementsFactory)
}
It("creates a user", func() {
runCommand("my-user", "my-password")
Expect(ui.Outputs).To(ContainSubstrings(
[]string{"Creating user", "my-user"},
[]string{"OK"},
[]string{"TIP"},
))
示例5:
Expect(ui.FailedWithUsage).To(BeTrue())
})
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())
示例6:
"username": "the-username",
"password": "the-password-3",
},
}))
Expect(ui.Outputs).To(ContainSubstrings([]string{"FAILED"}))
})
})
})
Describe("updates to the config", func() {
var l Login
BeforeEach(func() {
Config.SetApiEndpoint("api.the-old-endpoint.com")
Config.SetAccessToken("the-old-access-token")
Config.SetRefreshToken("the-old-refresh-token")
l = NewLogin(ui, Config, authRepo, endpointRepo, orgRepo, spaceRepo)
})
JustBeforeEach(func() {
testcmd.RunCommand(l, Flags, nil)
})
var ItShowsTheTarget = func() {
It("shows the target", func() {
Expect(ui.ShowConfigurationCalled).To(BeTrue())
})
}
var ItDoesntShowTheTarget = func() {