Skip to content

Commit 259f706

Browse files
authored
Merge pull request kubernetes#75834 from jlucktay/golint_pkg/auth/authorizer/abac
Golint pkg/auth/authorizer/abac
2 parents 16a0351 + dbb6965 commit 259f706

File tree

3 files changed

+14
-11
lines changed

3 files changed

+14
-11
lines changed

hack/.golint_failures

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ pkg/apis/storage/v1
6161
pkg/apis/storage/v1/util
6262
pkg/apis/storage/v1beta1
6363
pkg/apis/storage/v1beta1/util
64-
pkg/auth/authorizer/abac
6564
pkg/capabilities
6665
pkg/cloudprovider/providers/fake
6766
pkg/cloudprovider/providers/photon

pkg/auth/authorizer/abac/abac.go

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,9 @@ See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
1616

17+
// Package abac authorizes Kubernetes API actions using an Attribute-based access control scheme.
1718
package abac
1819

19-
// Policy authorizes Kubernetes API actions using an Attribute-based access
20-
// control scheme.
21-
2220
import (
2321
"bufio"
2422
"fmt"
@@ -31,6 +29,8 @@ import (
3129
"k8s.io/apiserver/pkg/authentication/user"
3230
"k8s.io/apiserver/pkg/authorization/authorizer"
3331
"k8s.io/kubernetes/pkg/apis/abac"
32+
33+
// Import latest API for init/side-effects
3434
_ "k8s.io/kubernetes/pkg/apis/abac/latest"
3535
"k8s.io/kubernetes/pkg/apis/abac/v0"
3636
)
@@ -49,10 +49,13 @@ func (p policyLoadError) Error() string {
4949
return fmt.Sprintf("error reading policy file %s: %v", p.path, p.err)
5050
}
5151

52-
type policyList []*abac.Policy
52+
// PolicyList is simply a slice of Policy structs.
53+
type PolicyList []*abac.Policy
5354

55+
// NewFromFile attempts to create a policy list from the given file.
56+
//
5457
// TODO: Have policies be created via an API call and stored in REST storage.
55-
func NewFromFile(path string) (policyList, error) {
58+
func NewFromFile(path string) (PolicyList, error) {
5659
// File format is one map per line. This allows easy concatenation of files,
5760
// comments in files, and identification of errors by line number.
5861
file, err := os.Open(path)
@@ -62,7 +65,7 @@ func NewFromFile(path string) (policyList, error) {
6265
defer file.Close()
6366

6467
scanner := bufio.NewScanner(file)
65-
pl := make(policyList, 0)
68+
pl := make(PolicyList, 0)
6669

6770
decoder := abac.Codecs.UniversalDecoder()
6871

@@ -220,8 +223,8 @@ func resourceMatches(p abac.Policy, a authorizer.Attributes) bool {
220223
return false
221224
}
222225

223-
// Authorizer implements authorizer.Authorize
224-
func (pl policyList) Authorize(a authorizer.Attributes) (authorizer.Decision, string, error) {
226+
// Authorize implements authorizer.Authorize
227+
func (pl PolicyList) Authorize(a authorizer.Attributes) (authorizer.Decision, string, error) {
225228
for _, p := range pl {
226229
if matches(*p, a) {
227230
return authorizer.DecisionAllow, "", nil
@@ -233,7 +236,8 @@ func (pl policyList) Authorize(a authorizer.Attributes) (authorizer.Decision, st
233236
// Then, add Caching only if needed.
234237
}
235238

236-
func (pl policyList) RulesFor(user user.Info, namespace string) ([]authorizer.ResourceRuleInfo, []authorizer.NonResourceRuleInfo, bool, error) {
239+
// RulesFor returns rules for the given user and namespace.
240+
func (pl PolicyList) RulesFor(user user.Info, namespace string) ([]authorizer.ResourceRuleInfo, []authorizer.NonResourceRuleInfo, bool, error) {
237241
var (
238242
resourceRules []authorizer.ResourceRuleInfo
239243
nonResourceRules []authorizer.NonResourceRuleInfo

pkg/auth/authorizer/abac/abac_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -815,7 +815,7 @@ func TestSubjectMatches(t *testing.T) {
815815
}
816816
}
817817

818-
func newWithContents(t *testing.T, contents string) (policyList, error) {
818+
func newWithContents(t *testing.T, contents string) (PolicyList, error) {
819819
f, err := ioutil.TempFile("", "abac_test")
820820
if err != nil {
821821
t.Fatalf("unexpected error creating policyfile: %v", err)

0 commit comments

Comments
 (0)