-
-
Notifications
You must be signed in to change notification settings - Fork 16
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
14 changed files
with
1,250 additions
and
12 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package client | ||
|
||
import ( | ||
"context" | ||
client "github.com/reddec/jsonrpc2/client" | ||
api "github.com/reddec/trusted-cgi/api" | ||
application "github.com/reddec/trusted-cgi/application" | ||
"sync/atomic" | ||
) | ||
|
||
func DefaultPoliciesAPI() *PoliciesAPIClient { | ||
return &PoliciesAPIClient{BaseURL: "https://127.0.0.1:3434/u/"} | ||
} | ||
|
||
type PoliciesAPIClient struct { | ||
BaseURL string | ||
sequence uint64 | ||
} | ||
|
||
// List all policies | ||
func (impl *PoliciesAPIClient) List(ctx context.Context, token *api.Token) (reply []application.Policy, err error) { | ||
err = client.CallHTTP(ctx, impl.BaseURL, "PoliciesAPI.List", atomic.AddUint64(&impl.sequence, 1), &reply, token) | ||
return | ||
} | ||
|
||
// Create new policy | ||
func (impl *PoliciesAPIClient) Create(ctx context.Context, token *api.Token, policy string, definition application.PolicyDefinition) (reply *application.Policy, err error) { | ||
err = client.CallHTTP(ctx, impl.BaseURL, "PoliciesAPI.Create", atomic.AddUint64(&impl.sequence, 1), &reply, token, policy, definition) | ||
return | ||
} | ||
|
||
// Remove policy | ||
func (impl *PoliciesAPIClient) Remove(ctx context.Context, token *api.Token, policy string) (reply bool, err error) { | ||
err = client.CallHTTP(ctx, impl.BaseURL, "PoliciesAPI.Remove", atomic.AddUint64(&impl.sequence, 1), &reply, token, policy) | ||
return | ||
} | ||
|
||
// Update policy definition | ||
func (impl *PoliciesAPIClient) Update(ctx context.Context, token *api.Token, policy string, definition application.PolicyDefinition) (reply bool, err error) { | ||
err = client.CallHTTP(ctx, impl.BaseURL, "PoliciesAPI.Update", atomic.AddUint64(&impl.sequence, 1), &reply, token, policy, definition) | ||
return | ||
} | ||
|
||
// Apply policy for the resource | ||
func (impl *PoliciesAPIClient) Apply(ctx context.Context, token *api.Token, lambda string, policy string) (reply bool, err error) { | ||
err = client.CallHTTP(ctx, impl.BaseURL, "PoliciesAPI.Apply", atomic.AddUint64(&impl.sequence, 1), &reply, token, lambda, policy) | ||
return | ||
} | ||
|
||
// Clear applied policy for the lambda | ||
func (impl *PoliciesAPIClient) Clear(ctx context.Context, token *api.Token, lambda string) (reply bool, err error) { | ||
err = client.CallHTTP(ctx, impl.BaseURL, "PoliciesAPI.Clear", atomic.AddUint64(&impl.sequence, 1), &reply, token, lambda) | ||
return | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,43 @@ | ||
package services | ||
|
||
import ( | ||
"context" | ||
"github.com/reddec/trusted-cgi/api" | ||
"github.com/reddec/trusted-cgi/application" | ||
) | ||
|
||
func NewPoliciesSrv(policies application.Policies) *policiesSrv { | ||
return &policiesSrv{policies: policies} | ||
} | ||
|
||
type policiesSrv struct { | ||
policies application.Policies | ||
} | ||
|
||
func (srv *policiesSrv) List(ctx context.Context, token *api.Token) ([]application.Policy, error) { | ||
return srv.policies.List(), nil | ||
} | ||
|
||
func (srv *policiesSrv) Create(ctx context.Context, token *api.Token, policy string, definition application.PolicyDefinition) (*application.Policy, error) { | ||
return srv.policies.Create(policy, definition) | ||
} | ||
|
||
func (srv *policiesSrv) Remove(ctx context.Context, token *api.Token, policy string) (bool, error) { | ||
err := srv.policies.Remove(policy) | ||
return err == nil, err | ||
} | ||
|
||
func (srv *policiesSrv) Update(ctx context.Context, token *api.Token, policy string, definition application.PolicyDefinition) (bool, error) { | ||
err := srv.policies.Update(policy, definition) | ||
return err == nil, err | ||
} | ||
|
||
func (srv *policiesSrv) Apply(ctx context.Context, token *api.Token, lambda string, policy string) (bool, error) { | ||
err := srv.policies.Apply(lambda, policy) | ||
return err == nil, err | ||
} | ||
|
||
func (srv *policiesSrv) Clear(ctx context.Context, token *api.Token, lambda string) (bool, error) { | ||
err := srv.policies.Clear(lambda) | ||
return err == nil, err | ||
} |
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
Oops, something went wrong.