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

Add workspace settings #206

Merged
merged 8 commits into from
Jul 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ lint: golangci-lint
gosec:
@gosec -exclude-generated ./...

generate:
generate-modules:
@./scripts/generate-all.sh $(OWNER) $(REPO)

devcheck: build vet lint gosec test testacc
Expand Down
90 changes: 89 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,90 @@
# pingone-go-sdk-v2
# PingOne Administration GO SDK

The PingOne GO SDK provides a set of functions and stucts that help with interacting with the PingOne public cloud API.

The code is intended to be delivered as a sample, until an official GO SDK is released from Ping Identity. As such, the code is highly likely to change significantly between releases.

Code for each service is generated with the help of the [OpenAPI Generator](https://openapi-generator.tech/).

## Packages

The SDK provides a core package, and a package per PingOne service, each with their own directory off the root of the project:

* **agreementmanagement** for the PingOne end-user agreements managements service
* **authorize** for the PingOne Authorize service
* **credentials** for the PingOne Credentials service, part of PingOne Neo
* **management** for the PingOne platform common and SSO services
* **mfa** for the PingOne MFA service
* **risk** for the PingOne Protect service
* **verify** for the PingOne Verify service, part of PingOne Neo

## Getting Started

The client can be invoked using the following syntax:

```go

...

import (
"context"

"github.com/patrickcping/pingone-go-sdk-v2/pingone"
)

...

config := &pingone.Config{
ClientID: clientId,
ClientSecret: clientSecret,
EnvironmentID: environmentId,
AccessToken: accessToken,
Region: region,
}

client, err := config.APIClient(ctx)
if err != nil {
return nil, err
}
```

The result is an object with clients initialised for each service:
* `client.AgreementManagementAPIClient`
* `client.AuthorizeAPIClient`
* `client.CredentialsAPIClient`
* `client.ManagementAPIClient`
* `client.MFAAPIClient`
* `client.RiskAPIClient`
* `client.VerifyAPIClient`

In the above, if an `AccessToken` is provided, this will be verified and used. If the `AccessToken` is not provided, the SDK will retrieve an access token from the provided `ClientID`, `ClientSecret`, `EnvironmentID` and `Region` parameters.

The client SDK defaults to production hostnames, and the `Region` is used to add the relevant suffix to the hostname. For example, `Europe` as a `Region` value with suffix the service hostname with `.eu`. Hostnames can be overridden with the optional `APIHostnameOverride`, `AgreementMgmtHostnameOverride`, and `AuthHostnameOverride` parameters.

An API call can be made against the API objects, as in the following example to get all environments in a tenant:

```go
...

resp, r, err := client.ManagementAPIClient.EnvironmentsApi.ReadAllEnvironments(ctx).Execute()
if err != nil {
return nil, err
}
...
```

## Contributing

Each package is generated from an underlying OpenAPI 3 specification. Currently the OpenAPI 3 specification is stored in the `./<<module>>/generate/pingone-<<module>>.yml` file, although this will be subject to change in the future.

* [**agreementmanagement** OpenAPI 3 Specification file](./authorize/generate/pingone-authorize.yml)
* [**authorize** OpenAPI 3 Specification file](./authorize/generate/pingone-authorize.yml)
* [**credentials** OpenAPI 3 Specification file](./credentials/generate/pingone-credentials.yml)
* [**management** OpenAPI 3 Specification file](./management/generate/pingone-management.yml)
* [**mfa** OpenAPI 3 Specification file](./mfa/generate/pingone-mfa.yml)
* [**risk** OpenAPI 3 Specification file](./risk/generate/pingone-risk.yml)
* [**verify** OpenAPI 3 Specification file](./verify/generate/pingone-verify.yml)

Once this file has been updated, from the module directory itself run `make generate`. This will generate the required `api_*.go` files, `model_*.go` files and associated documentation.

Before raising a Pull request, the resulting code can be checked using the `make devcheck` command. This will build, lint and verify the code.
24 changes: 0 additions & 24 deletions agreementmanagement/.gitignore

This file was deleted.

1 change: 1 addition & 0 deletions agreementmanagement/.openapi-generator-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ CHANGELOG.md
GNUmakefile
.version
test/*
generate/

client.go
18 changes: 16 additions & 2 deletions agreementmanagement/GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
TEST?=$$(go list ./...)
OWNER=patrickcping
REPO=pingone-go-sdk-v2
MODULE=agreementmanagement

default: build

build: fmtcheck
go build
@go mod tidy
@go mod vendor
@go build ./...

test: fmtcheck
go test $(TEST) $(TESTARGS) -timeout=5m
Expand Down Expand Up @@ -32,4 +37,13 @@ golangci-lint:
@echo "==> Checking source code with golangci-lint..."
@golangci-lint run ./...

.PHONY: build test testacc vet fmtcheck depscheck lint golangci-lint
gosec:
@gosec -exclude-generated ./...

generate:
@echo "==> Running generate for $(MODULE)..."
@./../scripts/generate.sh $(OWNER) $(REPO) $(MODULE)

devcheck: build vet lint gosec test testacc

.PHONY: build test testacc vet fmtcheck depscheck lint gosec golangci-lint generate
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package main

import (
"os"
"path/filepath"
"regexp"
)

func main() {
// Get the target directory from the command line argument
if len(os.Args) < 2 {
println("Usage: go run script.go <directory>")
return
}
dir := os.Args[1]

for _, rule := range replaceRules {
// Get a list of all files with the given extension in the directory
files, err := filepath.Glob(filepath.Join(dir, rule.fileSelectPattern))
if err != nil {
panic(err)
}

// Iterate over the files and apply the regex replacement rules
for _, file := range files {
// Read the file contents
content, err := os.ReadFile(filepath.Clean(file))
if err != nil {
panic(err)
}

// Apply the regex replacement rule
re := regexp.MustCompile(rule.pattern)
content = re.ReplaceAll(content, []byte(rule.repl))

// Write the updated file contents
err = os.WriteFile(file, content, os.ModePerm)
if err != nil {
panic(err)
}
}
}
}

var (
// Define the full list of regex replacement rules
replaceRules = []struct {
fileSelectPattern string
pattern string
repl string
}{}
)
1 change: 1 addition & 0 deletions authorize/.openapi-generator-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ CHANGELOG.md
GNUmakefile
.version
test/*
generate/*

client.go
18 changes: 16 additions & 2 deletions authorize/GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
TEST?=$$(go list ./...)
OWNER=patrickcping
REPO=pingone-go-sdk-v2
MODULE=authorize

default: build

build: fmtcheck
go build
@go mod tidy
@go mod vendor
@go build ./...

test: fmtcheck
go test $(TEST) $(TESTARGS) -timeout=5m
Expand Down Expand Up @@ -32,4 +37,13 @@ golangci-lint:
@echo "==> Checking source code with golangci-lint..."
@golangci-lint run ./...

.PHONY: build test testacc vet fmtcheck depscheck lint golangci-lint
gosec:
@gosec -exclude-generated ./...

generate:
@echo "==> Running generate for $(MODULE)..."
@./../scripts/generate.sh $(OWNER) $(REPO) $(MODULE)

devcheck: build vet lint gosec test testacc

.PHONY: build test testacc vet fmtcheck depscheck lint gosec golangci-lint generate
File renamed without changes.
52 changes: 52 additions & 0 deletions authorize/generate/postprocessing/generate-replace-regex.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package main

import (
"os"
"path/filepath"
"regexp"
)

func main() {
// Get the target directory from the command line argument
if len(os.Args) < 2 {
println("Usage: go run script.go <directory>")
return
}
dir := os.Args[1]

for _, rule := range replaceRules {
// Get a list of all files with the given extension in the directory
files, err := filepath.Glob(filepath.Join(dir, rule.fileSelectPattern))
if err != nil {
panic(err)
}

// Iterate over the files and apply the regex replacement rules
for _, file := range files {
// Read the file contents
content, err := os.ReadFile(filepath.Clean(file))
if err != nil {
panic(err)
}

// Apply the regex replacement rule
re := regexp.MustCompile(rule.pattern)
content = re.ReplaceAll(content, []byte(rule.repl))

// Write the updated file contents
err = os.WriteFile(file, content, os.ModePerm)
if err != nil {
panic(err)
}
}
}
}

var (
// Define the full list of regex replacement rules
replaceRules = []struct {
fileSelectPattern string
pattern string
repl string
}{}
)
1 change: 1 addition & 0 deletions credentials/.openapi-generator-ignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,6 @@ CHANGELOG.md
GNUmakefile
.version
test/*
generate/*

client.go
18 changes: 16 additions & 2 deletions credentials/GNUmakefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
TEST?=$$(go list ./...)
OWNER=patrickcping
REPO=pingone-go-sdk-v2
MODULE=credentials

default: build

build: fmtcheck
go build
@go mod tidy
@go mod vendor
@go build ./...

test: fmtcheck
go test $(TEST) $(TESTARGS) -timeout=5m
Expand Down Expand Up @@ -32,4 +37,13 @@ golangci-lint:
@echo "==> Checking source code with golangci-lint..."
@golangci-lint run ./...

.PHONY: build test testacc vet fmtcheck depscheck lint golangci-lint
gosec:
@gosec -exclude-generated ./...

generate:
@echo "==> Running generate for $(MODULE)..."
@./../scripts/generate.sh $(OWNER) $(REPO) $(MODULE)

devcheck: build vet lint gosec test testacc

.PHONY: build test testacc vet fmtcheck depscheck lint gosec golangci-lint generate
Loading