Skip to content

Commit

Permalink
Merge pull request #19 from TheJumpCloud/ts-updates-2018-10-13
Browse files Browse the repository at this point in the history
API v1 and v2 updates 2018-10-13
  • Loading branch information
tsmithjc committed Oct 15, 2018
2 parents 329ea34 + f296872 commit 5bae8c7
Show file tree
Hide file tree
Showing 241 changed files with 20,498 additions and 23,079 deletions.
206 changes: 134 additions & 72 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,121 +2,183 @@

### Description

This repository contains the Python client code for the JumpCloud API v1 and v2.
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.
This repository contains the Python client code for the JumpCloud API v1 and
v2. 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.

### Installing the Python Client

You can run the following pip commands in order to install the packages directly from Github:
You can run the following `pip` commands in order to install the packages
directly from GitHub:

```
pip install git+https://github.com/TheJumpCloud/jcapi-python.git#subdirectory=jcapiv1
pip install git+https://github.com/TheJumpCloud/jcapi-python.git#subdirectory=jcapiv2
```

Alternatively you can also pull this repository and install manually:
Change to the appropriate directory (jcapiv1 or jcapiv2) and then run the following command:
Alternatively you can also pull this repository and install manually. Change to
the appropriate directory (jcapiv1 or jcapiv2) and then run one of the
following commands.

To install the package for the local user:

```
$ python setup.py install --user
```

To install the package for all users:

```
$ sudo python setup.py install
```

### Authentication and Authorization

All endpoints support authentication via API key: see the [Authentication and Authorization](https://docs.jumpcloud.com/2.0/authentication-and-authorization/authentication-and-authorization-overview) section in our API docs.
All endpoints support authentication via API key: see the
[Authentication & Authorization](https://docs.jumpcloud.com/2.0/authentication-and-authorization/authentication-and-authorization-overview)
section in our API documentation.

Some Systems endpoints (in both API v1 and v2) also support the [System Context authorization](https://docs.jumpcloud.com/2.0/authentication-and-authorization/system-context) which allows an individual system to manage its information and resource associations.
Some systems endpoints (in both API v1 and v2) also support
[System Context Authorization](https://docs.jumpcloud.com/2.0/authentication-and-authorization/system-context)
which allows an individual system to manage its information and resource
associations.

### Usage Examples

For more detailed instructions, refer to each API's respective README file ([README for API v1](jcapiv1/README.md) and [README for API v2](jcapiv2/README.md)) and the generated docs under each folder.
For more detailed instructions, refer to each API version's respective README
file ([README for API v1](jcapiv1/README.md) and
[README for API v2](jcapiv2/README.md)) and the generated documentation under
each folder.

#### API v1 Example

#### API v1 example:
```python
"""JumpCloud API v1 example."""

import jcapiv1
from jcapiv1.rest import ApiException

...
content_type = 'application/json'
accept = 'application/json'

# set up the configuration object with your API key for authorization:
jcapiv1.configuration.api_key['x-api-key'] = '<YOUR_API_KEY>'

# instantiate the API object for the group of endpoints you need to use
# for instance for Systemusers API:
systemusersAPI = jcapiv1.SystemusersApi()

try:
# make an API call to retrieve all systemusers:
users = systemusersAPI.systemusers_list(content_type, accept)
print(users)
except ApiException as e:
print("Exception when calling SystemusersApi->systemusers_list: %s\n" % e)

try:
# make an API call to modify a specific user's last name:
put_request = jcapiv1.Systemuserputpost()
put_request.lastname = 'Updated Last Name'
systemusersAPI.systemusers_put('<YOUR_SYSTEMUSER_ID>', content_type, accept, body=put_request)
except ApiException as e:
print("Exception when calling SystemusersApi->systemusers_put: %s\n" % e)
API_KEY = "YOUR_API_KEY"
SYSTEM_USER_ID = "YOUR_SYSTEM_USER_ID"
SYSTEM_USER_EMAIL = "YOUR_SYSTEM_USER_EMAIL"
SYSTEM_USER_USERNAME = "YOUR_SYSTEM_USER_USERNAME"

CONTENT_TYPE = "application/json"
ACCEPT = "application/json"

# Set up the configuration object with your API key for authorization
CONFIGURATION = jcapiv1.Configuration()
CONFIGURATION.api_key['x-api-key'] = API_KEY

# Instantiate the API object for the group of endpoints you need to use,
# for instance the system users API
API_INSTANCE = jcapiv1.SystemusersApi(jcapiv1.ApiClient(CONFIGURATION))

def list_users():
"""Make an API call to retrieve all system users."""
try:
users = API_INSTANCE.systemusers_list(CONTENT_TYPE, ACCEPT)
print(users)
except ApiException as err:
print("Exception when calling SystemusersApi->systemusers_list: %s\n" % err)

def update_user():
"""Make an API call to update a system user."""
put_request = jcapiv1.Systemuserputpost(email=SYSTEM_USER_EMAIL, username=SYSTEM_USER_USERNAME)
put_request.lastname = "Updated Last Name"

try:
user = API_INSTANCE.systemusers_put(SYSTEM_USER_ID, CONTENT_TYPE, ACCEPT, body=put_request)
print(user)
except ApiException as err:
print("Exception when calling SystemusersApi->systemusers_put: %s\n" % err)

if __name__ == "__main__":
list_users()
update_user()

```

#### API v2 example:
#### API v2 Example

```python
"""JumpCloud API v2 example."""

import jcapiv2
from jcapiv2.rest import ApiException

...
content_type = 'application/json'
accept = 'application/json'
API_KEY = "YOUR_API_KEY"

CONTENT_TYPE = "application/json"
ACCEPT = "application/json"

# Set up the configuration object with your API key for authorization
CONFIGURATION = jcapiv2.Configuration()
CONFIGURATION.api_key['x-api-key'] = API_KEY

# set up the configuration object with your API key:
jcapiv2.configuration.api_key['x-api-key'] = '<YOUR_API_KEY>'
# Instantiate the API object for the group of endpoints you need to use,
# for instance the user groups API
API_INSTANCE = jcapiv2.UserGroupsApi(jcapiv2.ApiClient(CONFIGURATION))

# instantiate the API object for the group of endpoints you need to use
# for instance for User Groups API:
userGroupsAPI = jcapiv2.UserGroupsApi()
def get_user_groups():
"""Make an API call to retrieve all user groups."""
try:
user_groups = API_INSTANCE.groups_user_list(CONTENT_TYPE, ACCEPT)
print(user_groups)
except ApiException as err:
print("Exception when calling UserGroupsApi->groups_user_list: %s\n" % err)

try:
# make an API call to retrieve all user groups:
userGroups = userGroupsAPI.groups_user_list(content_type, accept)
print(userGroups)
except ApiException as e:
print("Exception when calling UserGroupsApi->groups_user_list: %s\n" % e)
if __name__ == "__main__":
get_user_groups()

```

#### System Context Authorization example:
#### System Context Authorization Example

```python
"""JumpCloud system context authorization example."""

import jcapiv2
from jcapiv2.rest import ApiException

content_type = 'application/json'
accept = 'application/json'
system_id = '<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
sys_context_auth = 'Signature keyId="system/<YOUR_SYSTEM_ID>",headers="request-line date",algorithm="rsa-sha256",signature="<YOUR_SYSTEM_SIGNATURE>"'
sys_context_date = 'Thu, 19 Oct 2017 17:27:57 GMT' # the current date on the system

# instantiate the API object for the group of endpoints you need to use
# for instance for User Groups API:
systemsAPI = jcapiv2.SystemsApi()

try:
# list the system groups this system is a member of:
# Note that we pass the System Context Authorization headers as the 'date' and 'authorization' parameters
groups = systemsAPI.graph_system_member_of(system_id, content_type, accept, date=sys_context_date, authorization=sys_context_auth)
print groups
except ApiException as e:
print("Exception when calling systemsAPI->graph_system_member_of: %s\n" % e)
# 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
SYSTEM_ID = "YOUR_SYSTEM_ID"
# The current date on the system, e.g. "Thu, 09 Aug 1990 14:25:15 GMT"
SYSTEM_DATE = "YOUR_SYSTEM_DATE"
SYSTEM_SIGNATURE = "YOUR_SYSTEM_SIGNATURE"
SYSTEM_CONTEXT_AUTH = (
'Signature keyId="system/{}",'
'headers="request-line date",'
'algorithm="rsa-sha256",'
'signature="{}"'
).format(SYSTEM_ID, SYSTEM_SIGNATURE)

CONTENT_TYPE = "application/json"
ACCEPT = "application/json"

# Set up the configuration object
CONFIGURATION = jcapiv2.Configuration()

# Instantiate the API object for the group of endpoints you need to use,
# for instance the systems API
API_INSTANCE = jcapiv2.SystemsApi(jcapiv2.ApiClient(CONFIGURATION))

def get_system_groups():
"""Make an API call to retrieve all system groups this system is a member of."""
try:
# Note the System Context Authorization headers are passed as arguments
system_groups = API_INSTANCE.graph_system_member_of(
SYSTEM_ID, CONTENT_TYPE, ACCEPT,
date=SYSTEM_DATE, authorization=SYSTEM_CONTEXT_AUTH,
)
print(system_groups)
except ApiException as err:
print("Exception when calling systemsAPI->graph_system_member_of: %s\n" % err)

if __name__ == "__main__":
get_system_groups()

```
2 changes: 1 addition & 1 deletion config_v1.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"packageName": "jcapiv1",
"packageVersion": "1.1.0"
"packageVersion": "1.2.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": "jcapiv2",
"packageVersion": "1.1.0"
"packageVersion": "1.2.0"
}
3 changes: 1 addition & 2 deletions jcapiv1/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
This Python package is automatically generated by the [Swagger Codegen](https://github.com/swagger-api/swagger-codegen) project:

- API version: 1.0
- Package version: 1.1.0
- Package version: 1.2.0
- Build package: io.swagger.codegen.languages.PythonClientCodegen

## Requirements.
Expand Down Expand Up @@ -160,7 +160,6 @@ 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)
Expand Down
2 changes: 1 addition & 1 deletion jcapiv1/docs/Command.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Name | Type | Description | Notes
**name** | **str** | | [optional]
**command** | **str** | The command to execute on the server. |
**command_type** | **str** | The Command OS | [optional]
**command_runners** | **list[str]** | an array of IDs of the Command Runner Users that can execute this command. | [optional]
**command_runners** | **list[str]** | An array of IDs of the Command Runner Users that can execute this command. | [optional]
**user** | **str** | The ID of the system user to run the command as. |
**sudo** | **bool** | | [optional]
**systems** | **list[str]** | An array of system IDs to run the command on. Not available if you are using Groups. | [optional]
Expand Down
2 changes: 1 addition & 1 deletion jcapiv1/docs/CommandslistResults.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ Name | Type | Description | Notes
**launch_type** | **str** | How the Command is executed. | [optional]
**listens_to** | **str** | | [optional]
**schedule** | **str** | A crontab that consists of: [ (seconds) (minutes) (hours) (days of month) (months) (weekdays) ] or [ immediate ]. If you send this as an empty string, it will run immediately. | [optional]
**trigger** | **str** | trigger to execute command. | [optional]
**trigger** | **str** | Trigger to execute command. | [optional]
**schedule_repeat_type** | **str** | When the command will repeat. | [optional]
**organization** | **str** | The ID of the Organization. | [optional]
**id** | **str** | The ID of the command. | [optional]
Expand Down
2 changes: 1 addition & 1 deletion jcapiv1/docs/OrganizationslistResults.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
## Properties
Name | Type | Description | Notes
------------ | ------------- | ------------- | -------------
**id** | **str** | the ID of the organization. | [optional]
**id** | **str** | The ID of the organization. | [optional]
**display_name** | **str** | The name of the organization. | [optional]
**logo_url** | **str** | The organization logo image URL. | [optional]

Expand Down
2 changes: 1 addition & 1 deletion jcapiv1/docs/Systemuser.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Name | Type | Description | Notes
**associated_tag_count** | **int** | | [optional]
**totp_enabled** | **bool** | | [optional]
**password_expiration_date** | **str** | | [optional]
**attributes** | [**list[SystemuserAttributes]**](SystemuserAttributes.md) | | [optional]
**attributes** | **list[object]** | | [optional]
**created** | **str** | | [optional]
**samba_service_user** | **bool** | | [optional]
**password_never_expires** | **bool** | | [optional]
Expand Down
10 changes: 0 additions & 10 deletions jcapiv1/docs/SystemuserAttributes.md

This file was deleted.

1 change: 0 additions & 1 deletion jcapiv1/jcapiv1/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
from jcapiv1.models.systemput_agent_bound_messages import SystemputAgentBoundMessages
from jcapiv1.models.systemslist import Systemslist
from jcapiv1.models.systemuser import Systemuser
from jcapiv1.models.systemuser_attributes import SystemuserAttributes
from jcapiv1.models.systemuserbinding import Systemuserbinding
from jcapiv1.models.systemuserbindingsput import Systemuserbindingsput
from jcapiv1.models.systemuserput import Systemuserput
Expand Down
2 changes: 1 addition & 1 deletion jcapiv1/jcapiv1/api_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def __init__(self, configuration=None, header_name=None, header_value=None,
self.default_headers[header_name] = header_value
self.cookie = cookie
# Set default User-Agent.
self.user_agent = 'Swagger-Codegen/1.1.0/python'
self.user_agent = 'Swagger-Codegen/1.2.0/python'

def __del__(self):
self.pool.close()
Expand Down
2 changes: 1 addition & 1 deletion jcapiv1/jcapiv1/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,5 +243,5 @@ def to_debug_report(self):
"OS: {env}\n"\
"Python Version: {pyversion}\n"\
"Version of the API: 1.0\n"\
"SDK Package Version: 1.1.0".\
"SDK Package Version: 1.2.0".\
format(env=sys.platform, pyversion=sys.version)
1 change: 0 additions & 1 deletion jcapiv1/jcapiv1/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@
from jcapiv1.models.systemput_agent_bound_messages import SystemputAgentBoundMessages
from jcapiv1.models.systemslist import Systemslist
from jcapiv1.models.systemuser import Systemuser
from jcapiv1.models.systemuser_attributes import SystemuserAttributes
from jcapiv1.models.systemuserbinding import Systemuserbinding
from jcapiv1.models.systemuserbindingsput import Systemuserbindingsput
from jcapiv1.models.systemuserput import Systemuserput
Expand Down
4 changes: 2 additions & 2 deletions jcapiv1/jcapiv1/models/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def command_type(self, command_type):
def command_runners(self):
"""Gets the command_runners of this Command. # noqa: E501
an array of IDs of the Command Runner Users that can execute this command. # noqa: E501
An array of IDs of the Command Runner Users that can execute this command. # noqa: E501
:return: The command_runners of this Command. # noqa: E501
:rtype: list[str]
Expand All @@ -194,7 +194,7 @@ def command_runners(self):
def command_runners(self, command_runners):
"""Sets the command_runners of this Command.
an array of IDs of the Command Runner Users that can execute this command. # noqa: E501
An array of IDs of the Command Runner Users that can execute this command. # noqa: E501
:param command_runners: The command_runners of this Command. # noqa: E501
:type: list[str]
Expand Down
4 changes: 2 additions & 2 deletions jcapiv1/jcapiv1/models/commandslist_results.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ def schedule(self, schedule):
def trigger(self):
"""Gets the trigger of this CommandslistResults. # noqa: E501
trigger to execute command. # noqa: E501
Trigger to execute command. # noqa: E501
:return: The trigger of this CommandslistResults. # noqa: E501
:rtype: str
Expand All @@ -245,7 +245,7 @@ def trigger(self):
def trigger(self, trigger):
"""Sets the trigger of this CommandslistResults.
trigger to execute command. # noqa: E501
Trigger to execute command. # noqa: E501
:param trigger: The trigger of this CommandslistResults. # noqa: E501
:type: str
Expand Down
Loading

0 comments on commit 5bae8c7

Please sign in to comment.