Skip to content

Commit e6e68f6

Browse files
authored
Merge pull request #18 from el-Mike/task/initial-unstable-release
task: cleanups, initial unstable release
2 parents ae5b305 + 8059678 commit e6e68f6

File tree

5 files changed

+28
-26
lines changed

5 files changed

+28
-26
lines changed

access_request.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,14 @@ type Context map[string]interface{}
66
// AccessRequest - describes a Subject's intention to perform some Actions against
77
// given Resource.
88
type AccessRequest struct {
9-
Subject Subject
9+
// Subject - subject (typically a user) that wants to perform given Actions.
10+
// Needs to implement Subject interface.
11+
Subject Subject
12+
// Resource - resource that given Subject wants to interact with.
13+
// Needs to implement Resource interface.
1014
Resource Resource
11-
Actions []string
12-
Context Context
15+
// Actions - list of operations Subject wants to perform on given Resource.
16+
Actions []string
17+
// Context - map of any additional values needed while checking Conditions.
18+
Context Context
1319
}

actions.go

Lines changed: 0 additions & 19 deletions
This file was deleted.

errors.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,17 @@ func (e *AccessDeniedError) Reason() error {
185185
return e.reason
186186
}
187187

188+
// FailedCondition - helper function for retrieving underlying failed Condition.
189+
func (e *AccessDeniedError) FailedCondition() Condition {
190+
if e.reason != nil {
191+
if conditionErr, ok := e.reason.(*ConditionNotSatisfiedError); ok {
192+
return conditionErr.condition
193+
}
194+
}
195+
196+
return nil
197+
}
198+
188199
// RequestMalformedError - thrown when AccessRequest is no correct or
189200
// does not contain all necessary information.
190201
type RequestMalformedError struct {
@@ -288,6 +299,7 @@ func (e *ConditionNotSatisfiedError) Error() string {
288299
return fmt.Sprintf("Condition: \"%v\" was not satisfied! %s", e.condition.Name(), e.reason.Error())
289300
}
290301

302+
// Reason - returns underlying reason (an error) of failing Condition.
291303
func (e *ConditionNotSatisfiedError) Reason() error {
292304
return e.reason
293305
}

value_descriptor.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,12 @@ import (
66

77
// ValueDescriptor - describes a value that will be tested in its parent Condition.
88
type ValueDescriptor struct {
9-
Source ValueSource `json:"source"`
10-
Field string `json:"field"`
11-
Value interface{} `json:"value"`
9+
// Source - source of the value, one of the predefined enum type (ValueSource).
10+
Source ValueSource `json:"source,omitempty" yaml:"source,omitempty"`
11+
// Field - field on the given ValueSource that should hold the value.
12+
Field string `json:"field,omitempty" yaml:"field,omitempty"`
13+
// Value - explicit value used when defining ValueSource.Explicit as value source.
14+
Value interface{} `json:"value,omitempty" yaml:"value,omitempty"`
1215
}
1316

1417
// GetValue - returns real value represented by given ValueDescriptor.

value_source.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ func (vs *ValueSource) UnmarshalJSON(jsonData []byte) error {
7070
return nil
7171
}
7272

73-
// UnmarshalJSON - unmarshals a string into ValueSource.
73+
// UnmarshalYAML - unmarshals a string into ValueSource.
7474
func (vs *ValueSource) UnmarshalYAML(value *yaml.Node) error {
7575
var sourceName string
7676

0 commit comments

Comments
 (0)