legal

package module
v0.0.0-...-4c61182 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 5, 2021 License: Apache-2.0 Imports: 9 Imported by: 1

README

This is AccelByte's Legal Go SDK for integrating with Legal in Go projects.

Usage

Importing package
import "github.com/AccelByte/legal-go-sdk"
cfg := &legal.Config{
    LegalBaseURL: "<Legal URL>",
}

client := legal.NewDefaultLegalClient(cfg)

It's recommended that you store the interface rather than the type since it enables you to mock the client during tests.

var client legal.LegalClient

client := legal.NewDefaultLegalClient(cfg)

So during tests, you can replace the client with:

var client legal.Client

client := iam.NewMockLegalClient() // or create your own mock implementation that suits your test case

Note

By default, the client can only do crucial policy version validation by requesting to Legal service.

To enable local validation, you need to call:

client.StartCachingCrucialLegal()

Then the client will automatically get all latest crucial policy version and refreshing them periodically. This enables you to do local policy version validation.

Validating Policy Version
Validating locally using cached policy versions:
claims, _ := client.ValidatePolicyVersions(policyVersions, clientID, country, namespace)

Note

If no policy versions cached for the affected clientID, it will try to call Legal to do remote validation

Health check

Whenever the Legal service went unhealthy, the client will know by detecting if any of the automated refresh goroutines has error.

You can check the health by:

client.HealthCheck()

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CrucialPolicyVersionResponse

type CrucialPolicyVersionResponse struct {
	AffectedClient map[string][]PolicyVersion
}

type DefaultLegalClient

type DefaultLegalClient struct {
	// contains filtered or unexported fields
}

func (*DefaultLegalClient) HealthCheck

func (client *DefaultLegalClient) HealthCheck() bool

func (*DefaultLegalClient) StartLocalCachingCrucial

func (client *DefaultLegalClient) StartLocalCachingCrucial() error

func (*DefaultLegalClient) ValidatePolicyVersions

func (client *DefaultLegalClient) ValidatePolicyVersions(claims *iam.JWTClaims) (bool, error)

type HTTPClient

type HTTPClient interface {
	Do(req *http.Request) (*http.Response, error)
}

type LegalClient

type LegalClient interface {
	StartLocalCachingCrucial() error

	ValidatePolicyVersions(claims *iam.JWTClaims) (bool, error)

	HealthCheck() bool
}

func NewDefaultLegalClient

func NewDefaultLegalClient(config *LegalConfig) LegalClient

NewDefaultLegalClient creates new Legal DefaultClient

func NewMockLegalClient

func NewMockLegalClient() LegalClient

type LegalConfig

type LegalConfig struct {
	LegalBaseURL                 string
	PublisherNamespace           string
	PolicyVersionRefreshInterval time.Duration
	Debug                        bool
}

type MockLegalClient

type MockLegalClient struct {
	Healthy bool
}

func (MockLegalClient) HealthCheck

func (client MockLegalClient) HealthCheck() bool

func (MockLegalClient) StartLocalCachingCrucial

func (client MockLegalClient) StartLocalCachingCrucial() error

func (MockLegalClient) ValidatePolicyVersions

func (client MockLegalClient) ValidatePolicyVersions(claims *iam.JWTClaims) (bool, error)

type PolicyVersion

type PolicyVersion struct {
	PolicyVersionID string
	Country         string
	Namespace       string
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL