forked from tkestack/tke
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
185 additions
and
125 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* Tencent is pleased to support the open source community by making TKEStack | ||
* available. | ||
* | ||
* Copyright (C) 2012-2019 Tencent. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the “License”); you may not use | ||
* this file except in compliance with the License. You may obtain a copy of the | ||
* License at | ||
* | ||
* https://opensource.org/licenses/Apache-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an “AS IS” BASIS, WITHOUT | ||
* WARRANTIES OF ANY KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations under the License. | ||
*/ | ||
|
||
package storage | ||
|
||
import ( | ||
"context" | ||
|
||
"tkestack.io/tke/pkg/util/log" | ||
|
||
"k8s.io/apimachinery/pkg/api/errors" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
"k8s.io/apimachinery/pkg/runtime" | ||
"k8s.io/apiserver/pkg/endpoints/request" | ||
"k8s.io/apiserver/pkg/registry/generic/registry" | ||
"k8s.io/apiserver/pkg/registry/rest" | ||
|
||
"tkestack.io/tke/api/auth" | ||
authinternalclient "tkestack.io/tke/api/client/clientset/internalversion/typed/auth/internalversion" | ||
) | ||
|
||
// UnbindingREST implements the REST endpoint. | ||
type UnbindingREST struct { | ||
*registry.Store | ||
|
||
authClient authinternalclient.AuthInterface | ||
} | ||
|
||
var _ = rest.Creater(&UnbindingREST{}) | ||
|
||
// New returns an empty object that can be used with Create after request data | ||
// has been put into it. | ||
func (r *UnbindingREST) New() runtime.Object { | ||
return &auth.Binding{} | ||
} | ||
|
||
func (r *UnbindingREST) Create(ctx context.Context, obj runtime.Object, createValidation rest.ValidateObjectFunc, options *metav1.CreateOptions) (runtime.Object, error) { | ||
requestInfo, ok := request.RequestInfoFrom(ctx) | ||
if !ok { | ||
return nil, errors.NewBadRequest("unable to get request info from context") | ||
} | ||
|
||
log.Info("requestinfo", log.Any("requestInfo", requestInfo)) | ||
|
||
bind := obj.(*auth.Binding) | ||
polObj, err := r.Get(ctx, requestInfo.Name, &metav1.GetOptions{}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
policy := polObj.(*auth.Policy) | ||
var remained []auth.Subject | ||
for _, sub := range policy.Status.Subjects { | ||
if !inSubjects(sub, bind.Subjects) { | ||
remained = append(remained, sub) | ||
} | ||
} | ||
|
||
policy.Status.Subjects = remained | ||
|
||
log.Info("policies", log.Any("subjects", policy.Status.Subjects)) | ||
return r.authClient.Policies().UpdateStatus(policy) | ||
} | ||
|
Oops, something went wrong.