本文整理汇总了Golang中github.com/cloudfoundry/cli/cf/configuration/coreconfig.ReadWriter.AccessToken方法的典型用法代码示例。如果您正苦于以下问题:Golang ReadWriter.AccessToken方法的具体用法?Golang ReadWriter.AccessToken怎么用?Golang ReadWriter.AccessToken使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cloudfoundry/cli/cf/configuration/coreconfig.ReadWriter
的用法示例。
在下文中一共展示了ReadWriter.AccessToken方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1:
Describe("GetApplications", func() {
It("tries to get applications from CC with a token handler", func() {
r.GetApplications()
Expect(ccClient.GetApplicationsCallCount()).To(Equal(1))
})
Context("when the client has updated tokens", func() {
BeforeEach(func() {
ccClient.TokensUpdatedReturns(true)
ccClient.GetUpdatedTokensReturns("updated-access-token", "updated-refresh-token")
})
It("stores the new tokens in the config", func() {
r.GetApplications()
Expect(config.AccessToken()).To(Equal("updated-access-token"))
Expect(config.RefreshToken()).To(Equal("updated-refresh-token"))
})
})
Context("when getting the applications succeeds", func() {
BeforeEach(func() {
ccClient.GetApplicationsReturns(getApplicationsJSON, nil)
})
It("returns a slice of application model objects", func() {
applications, err := r.GetApplications()
Expect(err).NotTo(HaveOccurred())
Expect(applications).To(Equal([]models.V3Application{
{
Name: "app-1-name",
示例2: NewRepositoryLocator
func NewRepositoryLocator(config coreconfig.ReadWriter, gatewaysByName map[string]net.Gateway, logger trace.Printer) (loc RepositoryLocator) {
strategy := strategy.NewEndpointStrategy(config.APIVersion())
cloudControllerGateway := gatewaysByName["cloud-controller"]
routingAPIGateway := gatewaysByName["routing-api"]
uaaGateway := gatewaysByName["uaa"]
loc.authRepo = authentication.NewUAAAuthenticationRepository(uaaGateway, config, net.NewRequestDumper(logger))
// ensure gateway refreshers are set before passing them by value to repositories
cloudControllerGateway.SetTokenRefresher(loc.authRepo)
uaaGateway.SetTokenRefresher(loc.authRepo)
loc.appBitsRepo = applicationbits.NewCloudControllerApplicationBitsRepository(config, cloudControllerGateway)
loc.appEventsRepo = appevents.NewCloudControllerAppEventsRepository(config, cloudControllerGateway, strategy)
loc.appFilesRepo = api_appfiles.NewCloudControllerAppFilesRepository(config, cloudControllerGateway)
loc.appRepo = applications.NewCloudControllerApplicationRepository(config, cloudControllerGateway)
loc.appSummaryRepo = NewCloudControllerAppSummaryRepository(config, cloudControllerGateway)
loc.appInstancesRepo = appinstances.NewCloudControllerAppInstancesRepository(config, cloudControllerGateway)
loc.authTokenRepo = NewCloudControllerServiceAuthTokenRepository(config, cloudControllerGateway)
loc.curlRepo = NewCloudControllerCurlRepository(config, cloudControllerGateway)
loc.domainRepo = NewCloudControllerDomainRepository(config, cloudControllerGateway, strategy)
loc.endpointRepo = NewEndpointRepository(cloudControllerGateway)
tlsConfig := net.NewTLSConfig([]tls.Certificate{}, config.IsSSLDisabled())
apiVersion, _ := semver.Make(config.APIVersion())
if apiVersion.GTE(cf.NoaaMinimumAPIVersion) {
consumer := consumer.New(config.DopplerEndpoint(), tlsConfig, http.ProxyFromEnvironment)
consumer.SetDebugPrinter(terminal.DebugPrinter{Logger: logger})
loc.logsRepo = logs.NewNoaaLogsRepository(config, consumer, loc.authRepo)
} else {
consumer := loggregator_consumer.New(config.LoggregatorEndpoint(), tlsConfig, http.ProxyFromEnvironment)
consumer.SetDebugPrinter(terminal.DebugPrinter{Logger: logger})
loc.logsRepo = logs.NewLoggregatorLogsRepository(config, consumer, loc.authRepo)
}
loc.organizationRepo = organizations.NewCloudControllerOrganizationRepository(config, cloudControllerGateway)
loc.passwordRepo = password.NewCloudControllerPasswordRepository(config, uaaGateway)
loc.quotaRepo = quotas.NewCloudControllerQuotaRepository(config, cloudControllerGateway)
loc.routeRepo = NewCloudControllerRouteRepository(config, cloudControllerGateway)
loc.routeServiceBindingRepo = NewCloudControllerRouteServiceBindingRepository(config, cloudControllerGateway)
loc.routingAPIRepo = NewRoutingAPIRepository(config, routingAPIGateway)
loc.stackRepo = stacks.NewCloudControllerStackRepository(config, cloudControllerGateway)
loc.serviceRepo = NewCloudControllerServiceRepository(config, cloudControllerGateway)
loc.serviceKeyRepo = NewCloudControllerServiceKeyRepository(config, cloudControllerGateway)
loc.serviceBindingRepo = NewCloudControllerServiceBindingRepository(config, cloudControllerGateway)
loc.serviceBrokerRepo = NewCloudControllerServiceBrokerRepository(config, cloudControllerGateway)
loc.servicePlanRepo = NewCloudControllerServicePlanRepository(config, cloudControllerGateway)
loc.servicePlanVisibilityRepo = NewCloudControllerServicePlanVisibilityRepository(config, cloudControllerGateway)
loc.serviceSummaryRepo = NewCloudControllerServiceSummaryRepository(config, cloudControllerGateway)
loc.spaceRepo = spaces.NewCloudControllerSpaceRepository(config, cloudControllerGateway)
loc.userProvidedServiceInstanceRepo = NewCCUserProvidedServiceInstanceRepository(config, cloudControllerGateway)
loc.userRepo = NewCloudControllerUserRepository(config, uaaGateway, cloudControllerGateway)
loc.buildpackRepo = NewCloudControllerBuildpackRepository(config, cloudControllerGateway)
loc.buildpackBitsRepo = NewCloudControllerBuildpackBitsRepository(config, cloudControllerGateway, appfiles.ApplicationZipper{})
loc.securityGroupRepo = security_groups.NewSecurityGroupRepo(config, cloudControllerGateway)
loc.stagingSecurityGroupRepo = staging.NewStagingSecurityGroupsRepo(config, cloudControllerGateway)
loc.runningSecurityGroupRepo = running.NewRunningSecurityGroupsRepo(config, cloudControllerGateway)
loc.securityGroupSpaceBinder = securitygroupspaces.NewSecurityGroupSpaceBinder(config, cloudControllerGateway)
loc.spaceQuotaRepo = spacequotas.NewCloudControllerSpaceQuotaRepository(config, cloudControllerGateway)
loc.featureFlagRepo = featureflags.NewCloudControllerFeatureFlagRepository(config, cloudControllerGateway)
loc.environmentVariableGroupRepo = environmentvariablegroups.NewCloudControllerEnvironmentVariableGroupsRepository(config, cloudControllerGateway)
loc.copyAppSourceRepo = copyapplicationsource.NewCloudControllerCopyApplicationSourceRepository(config, cloudControllerGateway)
client := v3client.NewClient(config.APIEndpoint(), config.AuthenticationEndpoint(), config.AccessToken(), config.RefreshToken())
loc.v3Repository = repository.NewRepository(config, client)
return
}
示例3:
"code": 10003,
"description": "You are not authorized to perform the requested action",
"error_code": "CF-NotAuthorized"
}`),
),
)
})
It("tries to unmarshal error response into provided resource", func() {
type apiErrResponse struct {
Code int `json:"code,omitempty"`
Description string `json:"description,omitempty"`
}
errResponse := new(apiErrResponse)
request, _ := ccGateway.NewRequest("GET", config.APIEndpoint()+"/v2/some-endpoint", config.AccessToken(), nil)
_, apiErr := ccGateway.PerformRequestForJSONResponse(request, errResponse)
Expect(apiErr).To(HaveOccurred())
Expect(errResponse.Code).To(Equal(10003))
})
It("ignores any unmarshal error and does not alter the api err response", func() {
request, _ := ccGateway.NewRequest("GET", config.APIEndpoint()+"/v2/some-endpoint", config.AccessToken(), nil)
_, apiErr := ccGateway.PerformRequestForJSONResponse(request, nil)
Expect(apiErr.Error()).To(Equal("Server error, status code: 401, error code: 10003, message: You are not authorized to perform the requested action"))
})
})
示例4:
err = auth.Authenticate(map[string]string{
"username": "[email protected]",
"password": "bar",
})
})
Describe("when login succeeds", func() {
BeforeEach(func() {
setupTestServer(successfulLoginRequest)
})
It("stores the access and refresh tokens in the config", func() {
Expect(handler).To(HaveAllRequestsCalled())
Expect(err).NotTo(HaveOccurred())
Expect(config.AuthenticationEndpoint()).To(Equal(testServer.URL))
Expect(config.AccessToken()).To(Equal("BEARER my_access_token"))
Expect(config.RefreshToken()).To(Equal("my_refresh_token"))
})
})
Describe("when login fails", func() {
BeforeEach(func() {
setupTestServer(unsuccessfulLoginRequest)
})
It("returns an error", func() {
Expect(handler).To(HaveAllRequestsCalled())
Expect(err).NotTo(BeNil())
Expect(err.Error()).To(Equal("Credentials were rejected, please try again."))
Expect(config.AccessToken()).To(BeEmpty())
Expect(config.RefreshToken()).To(BeEmpty())