Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Anthony/add expanders #63

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
3 changes: 2 additions & 1 deletion .genignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,5 @@ uhttp/
.ci
go.mod
go.sum
USAGE.md
USAGE.md
tools/
70 changes: 63 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ package main

import (
"context"
conductoronesdkgo "github.com/conductorone/conductorone-sdk-go/v2"
"github.com/conductorone/conductorone-sdk-go/v2/pkg/models/shared"
conductoronesdkgo "github.com/conductorone/conductorone-sdk-go"
"github.com/conductorone/conductorone-sdk-go/pkg/models/shared"
"log"
)

Expand Down Expand Up @@ -256,9 +256,9 @@ package main
import (
"context"
"errors"
conductoronesdkgo "github.com/conductorone/conductorone-sdk-go/v2"
"github.com/conductorone/conductorone-sdk-go/v2/pkg/models/sdkerrors"
"github.com/conductorone/conductorone-sdk-go/v2/pkg/models/shared"
conductoronesdkgo "github.com/conductorone/conductorone-sdk-go"
"github.com/conductorone/conductorone-sdk-go/pkg/models/sdkerrors"
"github.com/conductorone/conductorone-sdk-go/pkg/models/shared"
"log"
)

Expand Down Expand Up @@ -286,7 +286,63 @@ func main() {

```
<!-- No Error Handling [errors] -->
## SDK Expander

### Example

```go
package main

import (
"context"
conductoronesdkgo "github.com/conductorone/conductorone-sdk-go"
"github.com/conductorone/conductorone-sdk-go/pkg/models/shared"
)

func main() {
// Create SDK ...
req := shared.RequestCatalogSearchServiceSearchEntitlementsRequest{
AppEntitlementExpandMask: shared.AppEntitlementExpandMask{
Paths: []string{"*"},
},
}
resp, err := s.sdk.RequestCatalogSearch.SearchEntitlements(ctx, &req)
if err != nil {
return nil, err
}

response := resp.RequestCatalogSearchServiceSearchEntitlementsResponse
if response == nil {
return nil, nil
}

getStructWithPaths := func(response shared.AppEntitlementView) *shared.AppEntitlementView {
return &response
}

expandedResponse, err := GetExpandResponse(response.List, response.Expanded, getStructWithPaths, newMockEntitlement)
if err != nil {
return nil, err
}
return expandedResponse, nil

}

type mockEntitlement struct {
*shared.AppEntitlement
Expanded map[string]*any
}

func newMockEntitlement(x shared.AppEntitlementView, expanded map[string]*any) *mockEntitlement {
entitlement := x.GetAppEntitlement()

return &mockEntitlement{
AppEntitlement: entitlement,
Expanded: expanded,
}
}

```

## SDK Example Usage with Custom Server/Tenant

Expand All @@ -297,8 +353,8 @@ package main

import (
"context"
conductoronesdkgo "github.com/conductorone/conductorone-sdk-go/v2"
"github.com/conductorone/conductorone-sdk-go/v2/pkg/models/shared"
conductoronesdkgo "github.com/conductorone/conductorone-sdk-go"
"github.com/conductorone/conductorone-sdk-go/pkg/models/shared"
"log"
)

Expand Down
64 changes: 60 additions & 4 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ package main

import (
"context"
conductoronesdkgo "github.com/conductorone/conductorone-sdk-go/v2"
"github.com/conductorone/conductorone-sdk-go/v2/pkg/models/shared"
conductoronesdkgo "github.com/conductorone/conductorone-sdk-go"
"github.com/conductorone/conductorone-sdk-go/pkg/models/shared"
"log"
)

Expand Down Expand Up @@ -36,7 +36,63 @@ func main() {

```
<!-- No SDK Example Usage [usage] -->
## SDK Expander

### Example

```go
package main

import (
"context"
conductoronesdkgo "github.com/conductorone/conductorone-sdk-go"
"github.com/conductorone/conductorone-sdk-go/pkg/models/shared"
)

func main() {
// Create SDK ...
req := shared.RequestCatalogSearchServiceSearchEntitlementsRequest{
AppEntitlementExpandMask: shared.AppEntitlementExpandMask{
Paths: []string{"*"},
},
}
resp, err := s.sdk.RequestCatalogSearch.SearchEntitlements(ctx, &req)
if err != nil {
return nil, err
}

response := resp.RequestCatalogSearchServiceSearchEntitlementsResponse
if response == nil {
return nil, nil
}

getStructWithPaths := func(response shared.AppEntitlementView) *shared.AppEntitlementView {
return &response
}

expandedResponse, err := GetExpandResponse(response.List, response.Expanded, getStructWithPaths, newMockEntitlement)
if err != nil {
return nil, err
}
return expandedResponse, nil

}

type mockEntitlement struct {
*shared.AppEntitlement
Expanded map[string]*any
}

func newMockEntitlement(x shared.AppEntitlementView, expanded map[string]*any) *mockEntitlement {
entitlement := x.GetAppEntitlement()

return &mockEntitlement{
AppEntitlement: entitlement,
Expanded: expanded,
}
}

```
## SDK Example Usage with Custom Server/Tenant

### Example
Expand All @@ -46,8 +102,8 @@ package main

import (
"context"
conductoronesdkgo "github.com/conductorone/conductorone-sdk-go/v2"
"github.com/conductorone/conductorone-sdk-go/v2/pkg/models/shared"
conductoronesdkgo "github.com/conductorone/conductorone-sdk-go"
"github.com/conductorone/conductorone-sdk-go/pkg/models/shared"
"log"
)

Expand Down
Loading