forked from vmware-archive/octant
-
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.
Expose client state as an interface from service
[vmware-archive#2305] Signed-off-by: vikram yadav <[email protected]>
- Loading branch information
vikram yadav
committed
Apr 14, 2021
1 parent
11bfafc
commit 42a1d0e
Showing
8 changed files
with
111 additions
and
39 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package plugin | ||
|
||
type Filter interface { | ||
Key() string | ||
Value() string | ||
} | ||
|
||
type clientFilter struct { | ||
key string | ||
value string | ||
} | ||
|
||
func (cf clientFilter) Key() string { | ||
return cf.key | ||
} | ||
|
||
func (cf clientFilter) Value() string { | ||
return cf.value | ||
} |
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,50 @@ | ||
package plugin | ||
|
||
import ( | ||
"context" | ||
|
||
ocontext "github.com/vmware-tanzu/octant/internal/context" | ||
) | ||
|
||
type ClientState interface { | ||
ClientID() string | ||
Filters() []Filter | ||
Namespace() string | ||
ContextName() string | ||
} | ||
|
||
func ClientStateFrom(ctx context.Context) clientState { | ||
cs := ocontext.ClientStateFrom(ctx) | ||
filters := []Filter{} | ||
|
||
for _, f := range cs.Filters { | ||
filters = append(filters, clientFilter{key: f.Key, value: f.Value}) | ||
} | ||
|
||
return clientState{ | ||
clientID: cs.ClientID, | ||
filters: filters, | ||
namespace: cs.Namespace, | ||
contextName: cs.ContextName, | ||
} | ||
} | ||
|
||
type clientState struct { | ||
clientID string | ||
filters []Filter | ||
namespace string | ||
contextName string | ||
} | ||
|
||
func (c clientState) ClientID() string { | ||
return c.clientID | ||
} | ||
func (c clientState) Filters() []Filter { | ||
return c.filters | ||
} | ||
func (c clientState) Namespace() string { | ||
return c.namespace | ||
} | ||
func (c clientState) ContextName() string { | ||
return c.contextName | ||
} |
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
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