本文整理汇总了Golang中github.com/openshift/origin/pkg/oauth/api.Resource函数的典型用法代码示例。如果您正苦于以下问题:Golang Resource函数的具体用法?Golang Resource怎么用?Golang Resource使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Resource函数的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: NewREST
// NewREST returns a RESTStorage object that will work against oauth clients
func NewREST(s storage.Interface, clientGetter oauthclient.Getter) *REST {
store := &etcdgeneric.Etcd{
NewFunc: func() runtime.Object { return &api.OAuthClientAuthorization{} },
NewListFunc: func() runtime.Object { return &api.OAuthClientAuthorizationList{} },
KeyRootFunc: func(ctx kapi.Context) string {
return EtcdPrefix
},
KeyFunc: func(ctx kapi.Context, name string) (string, error) {
return util.NoNamespaceKeyFunc(ctx, EtcdPrefix, name)
},
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*api.OAuthClientAuthorization).Name, nil
},
PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
return oauthclientauthorization.Matcher(label, field)
},
QualifiedResource: api.Resource("oauthclientauthorizations"),
Storage: s,
}
store.CreateStrategy = oauthclientauthorization.NewStrategy(clientGetter)
store.UpdateStrategy = oauthclientauthorization.NewStrategy(clientGetter)
return &REST{*store}
}
开发者ID:RomainVabre,项目名称:origin,代码行数:27,代码来源:etcd.go
示例2: NewREST
// NewREST returns a RESTStorage object that will work against oauth clients
func NewREST(optsGetter restoptions.Getter) (*REST, error) {
store := ®istry.Store{
NewFunc: func() runtime.Object { return &api.OAuthClient{} },
NewListFunc: func() runtime.Object { return &api.OAuthClientList{} },
KeyRootFunc: func(ctx kapi.Context) string {
return EtcdPrefix
},
KeyFunc: func(ctx kapi.Context, name string) (string, error) {
return util.NoNamespaceKeyFunc(ctx, EtcdPrefix, name)
},
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*api.OAuthClient).Name, nil
},
PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
return oauthclient.Matcher(label, field)
},
QualifiedResource: api.Resource("oauthclients"),
CreateStrategy: oauthclient.Strategy,
UpdateStrategy: oauthclient.Strategy,
}
if err := restoptions.ApplyOptions(optsGetter, store, EtcdPrefix); err != nil {
return nil, err
}
return &REST{*store}, nil
}
开发者ID:Xmagicer,项目名称:origin,代码行数:30,代码来源:etcd.go
示例3: NewREST
// NewREST returns a RESTStorage object that will work against authorize tokens
func NewREST(optsGetter restoptions.Getter, clientGetter oauthclient.Getter) (*REST, error) {
strategy := oauthauthorizetoken.NewStrategy(clientGetter)
store := ®istry.Store{
NewFunc: func() runtime.Object { return &api.OAuthAuthorizeToken{} },
NewListFunc: func() runtime.Object { return &api.OAuthAuthorizeTokenList{} },
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*api.OAuthAuthorizeToken).Name, nil
},
PredicateFunc: func(label labels.Selector, field fields.Selector) *generic.SelectionPredicate {
return oauthauthorizetoken.Matcher(label, field)
},
TTLFunc: func(obj runtime.Object, existing uint64, update bool) (uint64, error) {
token := obj.(*api.OAuthAuthorizeToken)
expires := uint64(token.ExpiresIn)
return expires, nil
},
QualifiedResource: api.Resource("oauthauthorizetokens"),
CreateStrategy: strategy,
UpdateStrategy: strategy,
}
if err := restoptions.ApplyOptions(optsGetter, store, false, storage.NoTriggerPublisher); err != nil {
return nil, err
}
return &REST{store}, nil
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:28,代码来源:etcd.go
示例4: Get
// Get retrieves the OAuthClient from the indexer for a given namespace and name.
func (s oAuthClientNamespaceLister) Get(name string) (*api.OAuthClient, error) {
obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name)
if err != nil {
return nil, err
}
if !exists {
return nil, errors.NewNotFound(api.Resource("oauthclient"), name)
}
return obj.(*api.OAuthClient), nil
}
开发者ID:xgwang-zte,项目名称:origin,代码行数:11,代码来源:oauthclient.go
示例5: NewREST
// NewREST returns a RESTStorage object that will work against access tokens
func NewREST(optsGetter restoptions.Getter, clientGetter oauthclient.Getter, backends ...storage.Interface) (*REST, error) {
strategy := oauthaccesstoken.NewStrategy(clientGetter)
store := ®istry.Store{
NewFunc: func() runtime.Object { return &api.OAuthAccessToken{} },
NewListFunc: func() runtime.Object { return &api.OAuthAccessTokenList{} },
KeyRootFunc: func(ctx kapi.Context) string {
return EtcdPrefix
},
KeyFunc: func(ctx kapi.Context, name string) (string, error) {
return util.NoNamespaceKeyFunc(ctx, EtcdPrefix, name)
},
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*api.OAuthAccessToken).Name, nil
},
PredicateFunc: func(label labels.Selector, field fields.Selector) generic.Matcher {
return oauthaccesstoken.Matcher(label, field)
},
TTLFunc: func(obj runtime.Object, existing uint64, update bool) (uint64, error) {
token := obj.(*api.OAuthAccessToken)
expires := uint64(token.ExpiresIn)
return expires, nil
},
QualifiedResource: api.Resource("oauthaccesstokens"),
CreateStrategy: strategy,
UpdateStrategy: strategy,
}
if err := restoptions.ApplyOptions(optsGetter, store, EtcdPrefix); err != nil {
return nil, err
}
if len(backends) > 0 {
// Build identical stores that talk to a single etcd, so we can verify the token is distributed after creation
watchers := []rest.Watcher{}
for i := range backends {
watcher := *store
watcher.Storage = backends[i]
watchers = append(watchers, &watcher)
}
// Observe the cluster for the particular resource version, requiring at least one backend to succeed
observer := observe.NewClusterObserver(store.Storage.Versioner(), watchers, 1)
// After creation, wait for the new token to propagate
store.AfterCreate = func(obj runtime.Object) error {
return observer.ObserveResourceVersion(obj.(*api.OAuthAccessToken).ResourceVersion, 5*time.Second)
}
}
return &REST{store}, nil
}
开发者ID:Xmagicer,项目名称:origin,代码行数:52,代码来源:etcd.go
示例6: TestAuthenticateTokenNotFound
func TestAuthenticateTokenNotFound(t *testing.T) {
tokenRegistry := &test.AccessTokenRegistry{Err: apierrs.NewNotFound(oapi.Resource("OAuthAccessToken"), "token")}
userRegistry := usertest.NewUserRegistry()
tokenAuthenticator := NewTokenAuthenticator(tokenRegistry, userRegistry, identitymapper.NoopGroupMapper{})
userInfo, found, err := tokenAuthenticator.AuthenticateToken("token")
if found {
t.Error("Found token, but it should be missing!")
}
if err == nil {
t.Error("Expected not found error")
}
if !apierrs.IsNotFound(err) {
t.Error("Expected not found error")
}
if userInfo != nil {
t.Errorf("Unexpected user: %v", userInfo)
}
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:19,代码来源:registry_test.go
示例7: NewREST
// NewREST returns a RESTStorage object that will work against oauth clients
func NewREST(optsGetter restoptions.Getter) (*REST, error) {
store := ®istry.Store{
NewFunc: func() runtime.Object { return &api.OAuthClient{} },
NewListFunc: func() runtime.Object { return &api.OAuthClientList{} },
ObjectNameFunc: func(obj runtime.Object) (string, error) {
return obj.(*api.OAuthClient).Name, nil
},
PredicateFunc: func(label labels.Selector, field fields.Selector) *generic.SelectionPredicate {
return oauthclient.Matcher(label, field)
},
QualifiedResource: api.Resource("oauthclients"),
CreateStrategy: oauthclient.Strategy,
UpdateStrategy: oauthclient.Strategy,
}
if err := restoptions.ApplyOptions(optsGetter, store, false, storage.NoTriggerPublisher); err != nil {
return nil, err
}
return &REST{*store}, nil
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:23,代码来源:etcd.go
示例8: TestClusterReaderCoverage
func TestClusterReaderCoverage(t *testing.T) {
testutil.RequireEtcd(t)
defer testutil.DumpEtcdOnFailure(t)
_, clusterAdminKubeConfig, err := testserver.StartTestMasterAPI()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
clusterAdminClient, err := testutil.GetClusterAdminClient(clusterAdminKubeConfig)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
discoveryClient := client.NewDiscoveryClient(clusterAdminClient.RESTClient)
// (map[string]*unversioned.APIResourceList, error)
allResourceList, err := discoveryClient.ServerResources()
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
allResources := map[unversioned.GroupResource]bool{}
for _, resources := range allResourceList {
version, err := unversioned.ParseGroupVersion(resources.GroupVersion)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
for _, resource := range resources.APIResources {
allResources[version.WithResource(resource.Name).GroupResource()] = true
}
}
escalatingResources := map[unversioned.GroupResource]bool{
oauthapi.Resource("oauthauthorizetokens"): true,
oauthapi.Resource("oauthaccesstokens"): true,
oauthapi.Resource("oauthclients"): true,
imageapi.Resource("imagestreams/secrets"): true,
kapi.Resource("secrets"): true,
kapi.Resource("pods/exec"): true,
kapi.Resource("pods/proxy"): true,
kapi.Resource("pods/portforward"): true,
kapi.Resource("nodes/proxy"): true,
kapi.Resource("services/proxy"): true,
}
readerRole, err := clusterAdminClient.ClusterRoles().Get(bootstrappolicy.ClusterReaderRoleName)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
for _, rule := range readerRole.Rules {
for _, group := range rule.APIGroups {
for resource := range rule.Resources {
gr := unversioned.GroupResource{Group: group, Resource: resource}
if escalatingResources[gr] {
t.Errorf("cluster-reader role has escalating resource %v. Check pkg/cmd/server/bootstrappolicy/policy.go.", gr)
}
delete(allResources, gr)
}
}
}
// remove escalating resources that cluster-reader should not have access to
for resource := range escalatingResources {
delete(allResources, resource)
}
// remove resources without read APIs
nonreadingResources := []unversioned.GroupResource{
buildapi.Resource("buildconfigs/instantiatebinary"), buildapi.Resource("buildconfigs/instantiate"), buildapi.Resource("builds/clone"),
deployapi.Resource("deploymentconfigrollbacks"), deployapi.Resource("generatedeploymentconfigs"), deployapi.Resource("deploymentconfigs/rollback"),
imageapi.Resource("imagestreamimports"), imageapi.Resource("imagestreammappings"),
extensionsapi.Resource("deployments/rollback"),
kapi.Resource("pods/attach"), kapi.Resource("namespaces/finalize"),
}
for _, resource := range nonreadingResources {
delete(allResources, resource)
}
// anything left in the map is missing from the permissions
if len(allResources) > 0 {
t.Errorf("cluster-reader role is missing %v. Check pkg/cmd/server/bootstrappolicy/policy.go.", allResources)
}
}
开发者ID:Xmagicer,项目名称:origin,代码行数:85,代码来源:authorization_test.go
示例9: TestRegistryAndServer
//.........这里部分代码省略.........
Client: validClient,
AuthSuccess: true,
AuthUser: &user.DefaultInfo{
Name: "user",
},
ClientAuth: &oapi.OAuthClientAuthorization{
UserName: "user",
ClientName: "test",
Scopes: []string{"user:full"},
},
Check: func(h *testHandlers, req *http.Request) {
if h.AuthNeed || h.GrantNeed || h.AuthErr != nil || h.GrantErr != nil || !h.HandleAuthorizeReq.Authorized || h.HandleAuthorizeResp.ErrorId != "" {
t.Errorf("unexpected flow: %#v, %#v, %#v", h, h.HandleAuthorizeReq, h.HandleAuthorizeResp)
return
}
if req == nil {
t.Errorf("unexpected nil assertion request")
return
}
if code := req.URL.Query().Get("code"); code == "" {
t.Errorf("expected query param 'code', got: %#v", req)
}
},
},
}
for _, testCase := range testCases {
h := &testHandlers{}
h.Authenticate = testCase.AuthSuccess
h.User = testCase.AuthUser
access, authorize := &test.AccessTokenRegistry{}, &test.AuthorizeTokenRegistry{}
client := &test.ClientRegistry{
Client: testCase.Client,
}
if testCase.Client == nil {
client.Err = apierrs.NewNotFound(oapi.Resource("OAuthClient"), "unknown")
}
grant := &test.ClientAuthorizationRegistry{
ClientAuthorization: testCase.ClientAuth,
}
if testCase.ClientAuth == nil {
grant.GetErr = apierrs.NewNotFound(oapi.Resource("OAuthClientAuthorization"), "test:test")
}
storage := registrystorage.New(access, authorize, client, NewUserConversion())
config := osinserver.NewDefaultServerConfig()
h.AuthorizeHandler = osinserver.AuthorizeHandlers{
handlers.NewAuthorizeAuthenticator(
h,
h,
h,
),
handlers.NewGrantCheck(
NewClientAuthorizationGrantChecker(grant),
h,
h,
),
}
server := osinserver.New(
config,
storage,
h,
osinserver.AccessHandlers{
handlers.NewDenyAccessAuthenticator(),
},
h,
)
mux := http.NewServeMux()
server.Install(mux, "")
s := httptest.NewServer(mux)
oaclientConfig := &osincli.ClientConfig{
ClientId: "test",
ClientSecret: "secret",
RedirectUrl: assertServer.URL + "/assert",
AuthorizeUrl: s.URL + "/authorize",
TokenUrl: s.URL + "/token",
Scope: testCase.Scope,
}
oaclient, err := osincli.NewClient(oaclientConfig)
if err != nil {
t.Fatalf("unexpected error: %v", err)
}
aReq := oaclient.NewAuthorizeRequest(osincli.CODE)
if _, err := http.Get(aReq.GetAuthorizeUrl().String()); err != nil {
t.Fatalf("unexpected error: %v", err)
}
var req *http.Request
select {
case out := <-ch:
req = out
default:
}
testCase.Check(h, req)
}
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:101,代码来源:registry_test.go
示例10: emptyAuthRegistry
func emptyAuthRegistry() *test.ClientAuthorizationRegistry {
return &test.ClientAuthorizationRegistry{
GetErr: kapierrors.NewNotFound(oapi.Resource("oauthclientauthorizations"), "foo"),
}
}
开发者ID:juanluisvaladas,项目名称:origin,代码行数:5,代码来源:grant_test.go
注:本文中的github.com/openshift/origin/pkg/oauth/api.Resource函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论