Skip to content

Commit

Permalink
Merge pull request #20 from TheJumpCloud/ts-updates-2018-09-28
Browse files Browse the repository at this point in the history
API v1 and v2 updates 2018-10-10
  • Loading branch information
tsmithjc committed Oct 10, 2018
2 parents 8c7ee76 + 64252fb commit 7395700
Show file tree
Hide file tree
Showing 40 changed files with 1,437 additions and 333 deletions.
38 changes: 26 additions & 12 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,36 +1,50 @@
### Swagger code generation
### Swagger Code Generation

This repository relies on the following docker file in order to run swagger-codegen inside a docker container:
https://hub.docker.com/r/jimschubert/swagger-codegen-cli/
This repository relies on the following Dockerfile in order to run
Swagger Codegen inside a Docker container:
https://hub.docker.com/r/jimschubert/swagger-codegen-cli/.

We're currently using the version 2.3.1 of swagger-codegen.
We're currently using version 2.3.1 of Swagger Codegen.

### Generating the API Client

Copy the API yaml files to the local `/input` directory.
Copy the Swagger specification YAML files to the local `./input` directory.

The API v1 and v2 yaml specs can be found using the StopLight export links on our documentation pages: `https://docs.jumpcloud.com/1.0` and `https://docs.jumpcloud.com/2.0`.
The API v1 and v2 files can be found using the OAS export link on our
documentation pages: https://docs.jumpcloud.com/1.0 and
https://docs.jumpcloud.com/2.0.

Update the version number for each package in `config_v1.json` or `config_v2.json`.
Update the version number for each package in `config_v1.json` or
`config_v2.json`.

To generate the API v1 or v2 client, run the commands below (assuming your API v1 and v2 yaml files are `input/index1.yaml` and `input/index2.yaml`):
To generate the API v1 or v2 client, run the commands below (assuming your
API v1 and v2 specification files are `./input/index1.yaml` and
`./input/index2.yaml`):

```
docker-compose run --rm swagger-codegen generate -i /swagger-api/yaml/index1.yaml -l go -c /config/config_v1.json -o /swagger-api/out/v1
docker-compose run --rm swagger-codegen generate -i /swagger-api/yaml/index2.yaml -l go -c /config/config_v2.json -o /swagger-api/out/v2
```
This will generate the API v1 and v2 client files under `output/v1` and `output/v2`.

Once you are satisfied with the generated API client, you can replace the existing files under the `v1` or `v2` folder with your generated files:
This will generate the API v1 and v2 client files under the local
`./output/v1` and `./output/v2` directories.

Once you are satisfied with the generated API client, you can replace the
existing files under the `v1` or `v2` directory with your generated files:

```
rm -rf v1
mv output/v1 .
rm -rf v2
mv output/v2 .
```

There currently is a bug with swagger-codegen where it generates redundant enums for certain structures (namely GraphType and GroupType).
Make sure to run the following commands in order to remove the enums declarations:
There currently is a bug with Swagger Codegen where it generates redundant
enums for certain structures (namely `GraphType` and `GroupType`).
Make sure to run the following commands in order to remove the enums
declarations:

```
sed '/type GraphType string/q' v2/graph_type.go > tmp && mv tmp v2/graph_type.go
sed '/type GroupType string/q' v2/group_type.go > tmp && mv tmp v2/group_type.go
Expand Down
81 changes: 45 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,92 +1,101 @@
## JCAPI-Go

### Description ###
### Description

This repository contains the Go client code for the JumpCloud API v1 & v2. This code is automatically generated using swagger-codegen.
It also provides the tools to generate the client code from the API yaml files, using swagger-codegen.
For detailed instructions on how to generate the code, see the [Contributing](CONTRIBUTING.md) section.

To access our old API v1 Go Client, please refer to [JCAPI](https://github.com/TheJumpCloud/jcapi). However this code repository is not up to date with current API functionality.
This repository contains the Go client code for the JumpCloud API v1 and v2.
This code is automatically generated using Swagger Codegen. It also provides
the tools to generate the client code from the API YAML files, using Swagger
Codegen. For detailed instructions on how to generate the code, see the
[Contributing](CONTRIBUTING.md) section.

To access our old API v1 Go client, please refer to
[JCAPI](https://github.com/TheJumpCloud/jcapi). However this code repository
is not up to date with current API functionality.

### Usage Examples

```golang
package main

import (
"context"
"fmt"

jcapiv2 "github.com/TheJumpCloud/jcapi-go/v2"
)

func main() {
apiKey := "YOUR_API_KEY"
userGroupID := "YOUR_GROUP_ID"

contentType := "application/json"
accept := "application/json"
userGroupId := "<YOUR_GROUP_ID>"

// instantiate the API client:
// Instantiate the API client
client := jcapiv2.NewAPIClient(jcapiv2.NewConfiguration())

// set up the API key via context:
// Set up the API key via context
auth := context.WithValue(context.TODO(), jcapiv2.ContextAPIKey, jcapiv2.APIKey{
Key: "<YOUR_API_KEY>",
Key: apiKey,
})

// make an API call to retrieve a specific user group by id:
userGroup, res, err := client.UserGroupsApi.GroupsUserGet(auth, userGroupId, contentType, accept, nil)

// Make an API call to retrieve a specific user group by ID
userGroup, res, err := client.UserGroupsApi.GroupsUserGet(auth, userGroupID, contentType, accept, nil)
if err != nil {
fmt.Printf("Error retrieving user group %s: %s - response = %+v\n", userGroupId, err, res)
fmt.Printf("Error retrieving user group %s: %s - response = %+v\n", userGroupID, err, res)
} else {
fmt.Printf("Details for User group %s: %+v\n", userGroupId, userGroup)
fmt.Printf("Details for User group %s: %+v\n", userGroupID, userGroup)
}
}

```

System Context Authorization example:

```golang
package main

import (
"context"
"fmt"

jcapiv2 "github.com/TheJumpCloud/jcapi-go/v2"
)

func main() {

// instantiate the API client:
client := jcapiv2.NewAPIClient(jcapiv2.NewConfiguration())
// Set headers for System Context Authorization. For detailed instructions on
// how to generate these headers, refer to:
// https://docs.jumpcloud.com/2.0/authentication-and-authorization/system-context
systemID := "YOUR_SYSTEM_ID"
systemDate := "YOUR_SYSTEM_DATE" // The current date on the system, e.g. "Tue, 10 Nov 2009 23:00:00 GMT"
systemSignature := "YOUR_SYSTEM_SIGNATURE"
systemContextAuth := fmt.Sprintf(`Signature keyId="system/%s",headers="request-line date",algorithm="rsa-sha256",signature="%s"`, systemID, systemSignature)

contentType := "application/json"
accept := "application/json"

systemId := "<YOUR_SYSTEM_ID>"

// set headers for the System Context Authorization:
// for detailed instructions on how to generate these headers,
// refer to: https://docs.jumpcloud.com/2.0/authentication-and-authorization/system-context
sysContextAuth := `Signature keyId="system/<YOUR_SYSTEM_ID>",headers="request-line date",algorithm="rsa-sha256",signature="<YOUR_SYSTEM_SIGNATURE>"`
sysContextDate := "Thu, 19 Oct 2017 17:27:57 GMT" // the current date on the system
// Instantiate the API client
client := jcapiv2.NewAPIClient(jcapiv2.NewConfiguration())

// add date and authorization to the list of optional parameters:
// Add date and authorization to the list of optional parameters
optParams := map[string]interface{}{
"date": sysContextDate,
"authorization": sysContextAuth,
"date": systemDate,
"authorization": systemContextAuth,
}

// list the system groups this system is a member of using the System Context Authorization parameters:
// since we authenticate via system context parameters, no need to set the API key in the context
groups, res, err := client.SystemsApi.GraphSystemMemberOf(context.TODO(), systemId, contentType, accept, optParams)

// List the system groups this system is a member of using the
// System Context Authorization parameters. Since we authenticate via the
// parameters, there is no need to set the API key in the context.
groups, res, err := client.SystemsApi.GraphSystemMemberOf(context.TODO(), systemID, contentType, accept, optParams)
if err != nil {
fmt.Printf("Error retrieving system groups for system %s: %s - response = %+v\n", systemId, err, res)
fmt.Printf("Error retrieving system groups for system %s: %s - response = %+v\n", systemID, err, res)
return
}
// print the system groups we just retrieved:

// Print the system groups we just retrieved
for _, group := range groups {
fmt.Printf("System group ID %s\n", group.Id)
}

return
}

```
2 changes: 1 addition & 1 deletion config_v1.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"packageName": "v1",
"packageVersion": "1.32.0"
"packageVersion": "1.33.0"
}
2 changes: 1 addition & 1 deletion config_v2.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"packageName": "v2",
"packageVersion": "1.32.0"
"packageVersion": "1.33.0"
}
5 changes: 4 additions & 1 deletion v1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
This API client was generated by the [swagger-codegen](https://github.com/swagger-api/swagger-codegen) project. By using the [swagger-spec](https://github.com/swagger-api/swagger-spec) from a remote server, you can easily generate an API client.

- API version: 1.0
- Package version: 1.32.0
- Package version: 1.33.0
- Build package: io.swagger.codegen.languages.GoClientCodegen

## Installation
Expand Down Expand Up @@ -101,9 +101,12 @@ Class | Method | HTTP request | Description
- [SystemputAgentBoundMessages](docs/SystemputAgentBoundMessages.md)
- [Systemslist](docs/Systemslist.md)
- [Systemuser](docs/Systemuser.md)
- [SystemuserAttributes](docs/SystemuserAttributes.md)
- [Systemuserbinding](docs/Systemuserbinding.md)
- [Systemuserbindingsput](docs/Systemuserbindingsput.md)
- [Systemuserput](docs/Systemuserput.md)
- [SystemuserputAddresses](docs/SystemuserputAddresses.md)
- [SystemuserputPhoneNumbers](docs/SystemuserputPhoneNumbers.md)
- [Systemuserputpost](docs/Systemuserputpost.md)
- [SystemuserputpostAddresses](docs/SystemuserputpostAddresses.md)
- [SystemuserputpostPhoneNumbers](docs/SystemuserputpostPhoneNumbers.md)
Expand Down
Loading

0 comments on commit 7395700

Please sign in to comment.