4. CEDAR utilities

The CEDAR client will provide all the links the the CEDAR API functionnalities such as get, post and updates on templates, template elements, folders, instances ect …

class client.CEDARClient[source]

A client for the CEDAR API

create_folder(endpoint_type, api_key, target_folder_id, new_folder_name, new_folder_description)[source]

Create a folder with new_folder_name in the target_folder_id location

Parameters:
  • endpoint_type – (str) the type of server to prompt
  • api_key – (str) your CEDAR user API key
  • target_folder_id – (str) he CEDAR target folder’s ID where the new folder will be created
  • new_folder_name – (str) the new folder name to create
  • new_folder_description – (str) the new folder description to create
Returns:

(dict) a request response

create_template(endpoint_type, api_key, folder_id, template_file)[source]

Post a new schema to the selected folder id

Parameters:
  • endpoint_type – (str) the type of server to prompt
  • api_key – (str) your CEDAR user API key
  • folder_id – (str) the CEDAR target folder’s ID
  • template_file – (str) the CEDAR target template’s ID
Returns:

(dict) a request response

create_template_element(endpoint_type, api_key, folder_id, template_resource)[source]

Create a new template element on the given server

Parameters:
  • endpoint_type – (str) the type of server to prompt
  • api_key – (str) your CEDAR user API key
  • folder_id – (str) the CEDAR target folder’s ID
  • template_resource – (dict) the resource to post
Returns:

(dict) a request response

delete_folder(endpoint_type, api_key, folder_id)[source]

Delete a given folder from the server

Parameters:
  • endpoint_type – (str) the type of server to prompt
  • api_key – (str) your CEDAR user API key
  • folder_id – (str) the CEDAR target folder’s ID
Returns:

(dict) a request response

get_folder_content(endpoint_type, api_key, folder_id)[source]

Get the content of a folder from CEDAR

Parameters:
  • endpoint_type – (str) the type of server to prompt
  • api_key – (str) your CEDAR user API key
  • folder_id – (str) the CEDAR target folder’s ID
Returns:

(dict) a request response

static get_headers(api_key)[source]

Method to build the HTTP request header

Parameters:api_key – (str) the API Key to your CEDAR account
Returns:(dict) the HTTP headers
get_template_content(endpoint_type, api_key, template_id)[source]

Get the content of a CEDAR template

Parameters:
  • endpoint_type – (str) the type of server to prompt
  • api_key – (str) your CEDAR user API key
  • template_id – (str) the CEDAR target template’s ID
Returns:

(dict) a request response

get_users(endpoint_type, api_key)[source]

Method to get all users from the server

Parameters:
  • endpoint_type – (str) url to the CEDAR selected server
  • api_key – (str) your CEDAR user API key
Returns:

(dict) a request response

static post(url, parameter, headers, directory)[source]

Method to post data to the CEDAR selected server and log the process

Parameters:
  • url – (str) the URL to the selected server
  • parameter – (dict) parameters of the HTTP request
  • headers – (dict) the header required by the HTTP request
  • directory – (str) the directory where to saved the log file
static select_endpoint(server_type)[source]

Method to select the server (prod or dev)

Parameters:server_type – (str) the type of server to select
Returns:(str) the URL corresponding to the selected server
update_template(endpoint_type, api_key, template_file)[source]

Update the content of template_file into the selected template

Parameters:
  • endpoint_type – (str) “staging” or “production”
  • api_key – (str) your CEDAR user API key
  • template_file – (str) the full path to a local template JSON file
Returns:

(dict) a request response

upload_element(server_alias, api_key, schema_file, remote_folder_id)[source]

Upload a template element to the server

Parameters:
  • server_alias – (str) the type of server to prompt
  • api_key – (str) your CEDAR user API key
  • schema_file – (str) the full path to a local template element JSON file
  • remote_folder_id – (str) the CEDAR target folder’s ID
Returns:

(dict) a request response

upload_resource(api_key, request_url, resource)[source]

Upload the given resource to the CEDAR server

Parameters:
  • api_key – (str) your CEDAR user API key
  • request_url – (str) the CEDAR server URL to post to
  • resource – (dict) the resource to upload
Returns:

(dict) a response text loaded as a dictionary

validate_element(server_alias, api_key, element)[source]

Method to validate a CEDAR template element

Parameters:
  • server_alias – (str) the URL to run the validation from
  • api_key – (str) your CEDAR user API key
  • element – (dict) the resource to validate as a template
Returns:

(dict) a request response

validate_instance(server_address, api_key, instance)[source]

Method to validate a JSON instance against the corresponding resource on CEDAR

Parameters:
  • server_address – (str) the CEDAR server URL
  • api_key – (str) your CEDAR user API key
  • instance – (dict) the resource to validate as an instance
Returns:

(dict) a request response

validate_resource(api_key, request_url, resource)[source]

Method to validate a resource against the server

Parameters:
  • api_key – (str) your CEDAR user API key
  • request_url – (str) the URL to run the validation from
  • resource – (dict) the resource to validate
Returns:

(dict) a request response

validate_template(server_alias, api_key, template)[source]

Method to validate a CEDAR template

Parameters:
  • server_alias – (str) the URL to run the validation from
  • api_key – (str) your CEDAR user API key
  • template – (dict) the resource to validate as a template
Returns:

(dict) a request response


The schema2cedar classes will help you transform your JSON schemas draft 04 into compatible CEDAR schemas

class schema2cedar.Schema2CedarBase[source]

The base converter class

Warning

This class should not be used! Use its children for converting to cedar template and template elements

static json_pretty_dump(json_object, output_file)[source]

Dump a given json in the given file

Parameters:
  • json_object (dict) – the input JSON to dump
  • output_file (str) – the file to dump the JSON to
Returns:

the dumping result

Return type:

string

static set_context()[source]

Set the base context for a given template

Returns:the base context
static set_prop_context(schema)[source]

Set the required context for the properties attribute of the given schema

Parameters:schema – an input JSON schema
Returns:the properties context required by CEDAR
static set_properties_base_item()[source]

Set the base properties required by CEDAR

Returns:the base property dictionary
static set_required_item(schema)[source]

Set the required items that a CEDAR schema needs for a given schema

Parameters:schema – the input schema
Returns:the dictionary of required items
static set_stripped_properties(schema)[source]

Set the properties of a given schema

Parameters:schema – the input schema
Returns:a dictionary of properties
static set_sub_context(schema)[source]

Set the context required by CEDAR for each individual attribute/field for a given schema

Parameters:schema – the input schema
Returns:the dictionary of required context for each field
static set_template_element_property_minimals(sub_context, schema)[source]

Set the minimal elements of the properties attributes of a given schema and its sub-context

Parameters:
  • sub_context – the schema sub-context
  • schema – the input schema
Returns:

(dict) a dictionary of the required properties for CEDAR conversion

class schema2cedar.Schema2CedarTemplate[source]

Schema 2 Template Converter, this is the one you want to use if you want to convert a schema into a template

convert_template(input_json_schema)[source]

Method to convert a given schema into a CEDAR template

Parameters:input_json_schema – the input JSON schema
Returns:the schema converted into a template
class schema2cedar.Schema2CedarTemplateElement[source]

Schema to TemplateElement converter.

Warning

Should only be used to convert schemas to template element. If you want to convert a schema to a template, use Schema2CedarTemplate (it will automatically create nested template elements for you)

convert_template_element(input_json_schema, **kwargs)[source]

Method to convert a given schema into a CEDAR template element

Parameters:
  • input_json_schema – the input schema
  • kwargs – optional parameter to provide the field name referencing that schema
Returns:

the schema converted to a CEDAR template element

find_sub_specs(schema, sub_spec_container)[source]

Inspect a given schema to find and load its schemas dependencies

Parameters:
  • schema – the input schema
  • sub_spec_container – a container that will hold the dependencies
Return sub_spec_container:
 

the filled container with the schema dependencies

static load_sub_spec(path_to_load, parent_schema, field_key)[source]

Load the given sub schema into memory

Parameters:
  • path_to_load – path to the sub schema
  • parent_schema – the parent schema that this sub-schema is referenced from
  • field_key – the parent schema field name that this sub-schema is referenced from
Returns:

the string containing the loaded JSON schema