Skip to content

Commit

Permalink
Adds SDK helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
arekkas authored and arekkas committed Apr 29, 2018
1 parent 2d4cd98 commit a1c2608
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 1 deletion.
37 changes: 37 additions & 0 deletions sdk/go/keto/sdk.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,44 @@
package keto

import (
"strings"

"github.com/ory/keto/sdk/go/keto/swagger"
"github.com/pkg/errors"
)

type SDK interface {
RoleSDK
WardenSDK
PolicySDK
}

type CodeGenSDK struct {
*swagger.RoleApi
*swagger.WardenApi
*swagger.PolicyApi

Configuration *Configuration
}

// Configuration configures the CodeGenSDK.
type Configuration struct {
// EndpointURL should point to the url of ORY Hydra, for example: http://localhost:4444
EndpointURL string
}

// CodeGenSDK instantiates a new CodeGenSDK instance or returns an error.
func NewCodeGenSDK(c *Configuration) (*CodeGenSDK, error) {
if c.EndpointURL == "" {
return nil, errors.New("Please specify the ORY Keto endpoint URL")
}

c.EndpointURL = strings.TrimRight(c.EndpointURL, "/")
sdk := &CodeGenSDK{
RoleApi: swagger.NewRoleApiWithBasePath(c.EndpointURL),
WardenApi: swagger.NewWardenApiWithBasePath(c.EndpointURL),
PolicyApi: swagger.NewPolicyApiWithBasePath(c.EndpointURL),
}

return sdk, nil
}
2 changes: 1 addition & 1 deletion sdk/go/keto/swagger/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ type Configuration struct {
UserAgent string `json:"userAgent,omitempty"`
APIClient *APIClient
Transport http.RoundTripper
Timeout *time.Duration `json:"timeout,omitempty"`
Timeout *time.Duration `json:"timeout,omitempty"`
}

func NewConfiguration() *Configuration {
Expand Down

0 comments on commit a1c2608

Please sign in to comment.