From 3cb0d652b4b237bab56d681b9c4cc31901bd9096 Mon Sep 17 00:00:00 2001 From: Guillaume Berche Date: Wed, 6 Dec 2017 18:52:17 +0100 Subject: [PATCH 1/6] custom schema generation to support intellij-hcl plugin --- cf.json | 1454 ++++++++++++++++++++++++++++ generate-schema/generate-schema.go | 173 ++++ 2 files changed, 1627 insertions(+) create mode 100644 cf.json create mode 100644 generate-schema/generate-schema.go diff --git a/cf.json b/cf.json new file mode 100644 index 000000000..9d7e1df52 --- /dev/null +++ b/cf.json @@ -0,0 +1,1454 @@ +{ + "name": "cf", + "type": "provider", + "version": "0.9.5", + "provider": { + "api_url": { + "Type": "TypeString", + "Required": true, + "Default": { + "Type": "string" + }, + "Elem": {} + }, + "ca_cert": { + "Type": "TypeString", + "Required": true, + "Default": { + "Type": "string" + }, + "Elem": {} + }, + "password": { + "Type": "TypeString", + "Required": true, + "Default": { + "Type": "string" + }, + "Elem": {} + }, + "skip_ssl_validation": { + "Type": "TypeBool", + "Required": true, + "Default": { + "Type": "string", + "Value": "true" + }, + "Elem": {} + }, + "uaa_client_id": { + "Type": "TypeString", + "Optional": true, + "Default": { + "Type": "string" + }, + "Elem": {} + }, + "uaa_client_secret": { + "Type": "TypeString", + "Optional": true, + "Default": { + "Type": "string" + }, + "Elem": {} + }, + "user": { + "Type": "TypeString", + "Required": true, + "Default": { + "Type": "string" + }, + "Elem": {} + } + }, + "resources": { + "cf_app": { + "add_content": { + "Type": "TypeList", + "Optional": true, + "Default": {}, + "Elem": { + "Type": "SchemaInfo", + "Info": { + "destination": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "source": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + } + } + } + }, + "buildpack": { + "Type": "TypeString", + "Optional": true, + "Computed": true, + "Default": {}, + "Elem": {} + }, + "command": { + "Type": "TypeString", + "Optional": true, + "Computed": true, + "Default": {}, + "Elem": {} + }, + "disk_quota": { + "Type": "TypeInt", + "Optional": true, + "Computed": true, + "Default": {}, + "Elem": {} + }, + "enable_ssh": { + "Type": "TypeBool", + "Optional": true, + "Computed": true, + "Default": {}, + "Elem": {} + }, + "environment": { + "Type": "TypeMap", + "Optional": true, + "Computed": true, + "Default": {}, + "Elem": {} + }, + "git": { + "Type": "TypeList", + "Optional": true, + "MaxItems": 1, + "ConflictsWith": [ + "url", + "github_release" + ], + "Default": {}, + "Elem": { + "Type": "SchemaInfo", + "Info": { + "branch": { + "Type": "TypeString", + "Optional": true, + "ConflictsWith": [ + "git.tag" + ], + "Default": {}, + "Elem": {} + }, + "key": { + "Type": "TypeString", + "Optional": true, + "Default": {}, + "Elem": {} + }, + "password": { + "Type": "TypeString", + "Optional": true, + "Default": {}, + "Elem": {} + }, + "tag": { + "Type": "TypeString", + "Optional": true, + "ConflictsWith": [ + "git.branch" + ], + "Default": {}, + "Elem": {} + }, + "url": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "user": { + "Type": "TypeString", + "Optional": true, + "Default": {}, + "Elem": {} + } + } + } + }, + "github_release": { + "Type": "TypeList", + "Optional": true, + "MaxItems": 1, + "ConflictsWith": [ + "url", + "git" + ], + "Default": {}, + "Elem": { + "Type": "SchemaInfo", + "Info": { + "filename": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "owner": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "repo": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "token": { + "Type": "TypeString", + "Optional": true, + "Default": {}, + "Elem": {} + }, + "version": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + } + } + } + }, + "health_check_http_endpoint": { + "Type": "TypeString", + "Optional": true, + "Computed": true, + "Default": {}, + "Elem": {} + }, + "health_check_timeout": { + "Type": "TypeInt", + "Optional": true, + "Computed": true, + "Default": {}, + "Elem": {} + }, + "health_check_type": { + "Type": "TypeString", + "Optional": true, + "Computed": true, + "Default": {}, + "Elem": {} + }, + "instances": { + "Type": "TypeInt", + "Optional": true, + "Default": {}, + "Elem": {} + }, + "memory": { + "Type": "TypeInt", + "Optional": true, + "Computed": true, + "Default": {}, + "Elem": {} + }, + "name": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "ports": { + "Type": "TypeSet", + "Optional": true, + "Computed": true, + "Default": {}, + "Elem": { + "Type": "SchemaElements", + "ElementsType": "TypeInt" + } + }, + "route": { + "Type": "TypeList", + "Optional": true, + "MaxItems": 1, + "Default": {}, + "Elem": { + "Type": "SchemaInfo", + "Info": { + "default_route": { + "Type": "TypeString", + "Optional": true, + "Default": {}, + "Elem": {} + }, + "default_route_mapping_id": { + "Type": "TypeString", + "Computed": true, + "Default": {}, + "Elem": {} + }, + "live_route": { + "Type": "TypeString", + "Optional": true, + "Default": {}, + "Elem": {} + }, + "live_route_mapping_id": { + "Type": "TypeString", + "Computed": true, + "Default": {}, + "Elem": {} + }, + "stage_route": { + "Type": "TypeString", + "Optional": true, + "Default": {}, + "Elem": {} + }, + "stage_route_mapping_id": { + "Type": "TypeString", + "Computed": true, + "Default": {}, + "Elem": {} + }, + "validation_script": { + "Type": "TypeString", + "Optional": true, + "Default": {}, + "Elem": {} + }, + "version": { + "Type": "TypeString", + "Optional": true, + "Default": {}, + "Elem": {} + } + } + } + }, + "service_binding": { + "Type": "TypeList", + "Optional": true, + "Default": {}, + "Elem": { + "Type": "SchemaInfo", + "Info": { + "binding_id": { + "Type": "TypeString", + "Computed": true, + "Default": {}, + "Elem": {} + }, + "credentials": { + "Type": "TypeMap", + "Computed": true, + "Default": {}, + "Elem": {} + }, + "params": { + "Type": "TypeMap", + "Optional": true, + "Default": {}, + "Elem": {} + }, + "service_instance": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + } + } + } + }, + "space": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "stack": { + "Type": "TypeString", + "Optional": true, + "Computed": true, + "Default": {}, + "Elem": {} + }, + "stopped": { + "Type": "TypeBool", + "Optional": true, + "Default": {}, + "Elem": {} + }, + "timeout": { + "Type": "TypeInt", + "Optional": true, + "Default": {}, + "Elem": {} + }, + "url": { + "Type": "TypeString", + "Optional": true, + "ConflictsWith": [ + "git", + "github_release" + ], + "Default": {}, + "Elem": {} + } + }, + "cf_asg": { + "name": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "rule": { + "Type": "TypeList", + "Required": true, + "Default": {}, + "Elem": { + "Type": "SchemaInfo", + "Info": { + "code": { + "Type": "TypeInt", + "Optional": true, + "Default": {}, + "Elem": {} + }, + "description": { + "Type": "TypeString", + "Optional": true, + "Default": {}, + "Elem": {} + }, + "destination": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "log": { + "Type": "TypeBool", + "Optional": true, + "Default": {}, + "Elem": {} + }, + "ports": { + "Type": "TypeString", + "Optional": true, + "Default": {}, + "Elem": {} + }, + "protocol": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "type": { + "Type": "TypeInt", + "Optional": true, + "Default": {}, + "Elem": {} + } + } + } + } + }, + "cf_buildpack": { + "enabled": { + "Type": "TypeBool", + "Optional": true, + "Computed": true, + "Default": {}, + "Elem": {} + }, + "git": { + "Type": "TypeList", + "Optional": true, + "MaxItems": 1, + "ConflictsWith": [ + "url", + "github_release" + ], + "Default": {}, + "Elem": { + "Type": "SchemaInfo", + "Info": { + "branch": { + "Type": "TypeString", + "Optional": true, + "ConflictsWith": [ + "git.tag" + ], + "Default": {}, + "Elem": {} + }, + "key": { + "Type": "TypeString", + "Optional": true, + "Default": {}, + "Elem": {} + }, + "password": { + "Type": "TypeString", + "Optional": true, + "Default": {}, + "Elem": {} + }, + "tag": { + "Type": "TypeString", + "Optional": true, + "ConflictsWith": [ + "git.branch" + ], + "Default": {}, + "Elem": {} + }, + "url": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "user": { + "Type": "TypeString", + "Optional": true, + "Default": {}, + "Elem": {} + } + } + } + }, + "github_release": { + "Type": "TypeList", + "Optional": true, + "MaxItems": 1, + "ConflictsWith": [ + "url", + "git" + ], + "Default": {}, + "Elem": { + "Type": "SchemaInfo", + "Info": { + "filename": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "owner": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "repo": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "token": { + "Type": "TypeString", + "Optional": true, + "Default": {}, + "Elem": {} + }, + "version": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + } + } + } + }, + "locked": { + "Type": "TypeBool", + "Optional": true, + "Computed": true, + "Default": {}, + "Elem": {} + }, + "name": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "position": { + "Type": "TypeInt", + "Optional": true, + "Computed": true, + "Default": {}, + "Elem": {} + }, + "url": { + "Type": "TypeString", + "Optional": true, + "ConflictsWith": [ + "git", + "github_release" + ], + "Default": {}, + "Elem": {} + } + }, + "cf_config": { + "feature_flags": { + "Type": "TypeList", + "Optional": true, + "MaxItems": 1, + "Default": {}, + "Elem": { + "Type": "SchemaInfo", + "Info": { + "app_bits_upload": { + "Type": "TypeString", + "Optional": true, + "Computed": true, + "Default": {}, + "Elem": {} + }, + "app_scaling": { + "Type": "TypeString", + "Optional": true, + "Computed": true, + "Default": {}, + "Elem": {} + }, + "diego_docker": { + "Type": "TypeString", + "Optional": true, + "Computed": true, + "Default": {}, + "Elem": {} + }, + "env_var_visibility": { + "Type": "TypeString", + "Optional": true, + "Computed": true, + "Default": {}, + "Elem": {} + }, + "private_domain_creation": { + "Type": "TypeString", + "Optional": true, + "Computed": true, + "Default": {}, + "Elem": {} + }, + "route_creation": { + "Type": "TypeString", + "Optional": true, + "Computed": true, + "Default": {}, + "Elem": {} + }, + "service_instance_creation": { + "Type": "TypeString", + "Optional": true, + "Computed": true, + "Default": {}, + "Elem": {} + }, + "set_roles_by_username": { + "Type": "TypeString", + "Optional": true, + "Computed": true, + "Default": {}, + "Elem": {} + }, + "space_developer_env_var_visibility": { + "Type": "TypeString", + "Optional": true, + "Computed": true, + "Default": {}, + "Elem": {} + }, + "space_scoped_private_broker_creation": { + "Type": "TypeString", + "Optional": true, + "Computed": true, + "Default": {}, + "Elem": {} + }, + "task_creation": { + "Type": "TypeString", + "Optional": true, + "Computed": true, + "Default": {}, + "Elem": {} + }, + "unset_roles_by_username": { + "Type": "TypeString", + "Optional": true, + "Computed": true, + "Default": {}, + "Elem": {} + }, + "user_org_creation": { + "Type": "TypeString", + "Optional": true, + "Computed": true, + "Default": {}, + "Elem": {} + } + } + } + } + }, + "cf_default_asg": { + "asgs": { + "Type": "TypeSet", + "Required": true, + "Default": {}, + "Elem": { + "Type": "SchemaElements", + "ElementsType": "TypeString" + } + }, + "name": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + } + }, + "cf_domain": { + "domain": { + "Type": "TypeString", + "Optional": true, + "Computed": true, + "Default": {}, + "Elem": {} + }, + "name": { + "Type": "TypeString", + "Optional": true, + "Computed": true, + "Default": {}, + "Elem": {} + }, + "org": { + "Type": "TypeString", + "Optional": true, + "ConflictsWith": [ + "router_group" + ], + "Default": {}, + "Elem": {} + }, + "router_group": { + "Type": "TypeString", + "Optional": true, + "ConflictsWith": [ + "org" + ], + "Default": {}, + "Elem": {} + }, + "router_type": { + "Type": "TypeString", + "Computed": true, + "Default": {}, + "Elem": {} + }, + "sub_domain": { + "Type": "TypeString", + "Optional": true, + "Computed": true, + "Default": {}, + "Elem": {} + } + }, + "cf_evg": { + "name": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "variables": { + "Type": "TypeMap", + "Required": true, + "Default": {}, + "Elem": {} + } + }, + "cf_org": { + "auditors": { + "Type": "TypeSet", + "Optional": true, + "Default": {}, + "Elem": { + "Type": "SchemaElements", + "ElementsType": "TypeString" + } + }, + "billing_managers": { + "Type": "TypeSet", + "Optional": true, + "Default": {}, + "Elem": { + "Type": "SchemaElements", + "ElementsType": "TypeString" + } + }, + "managers": { + "Type": "TypeSet", + "Optional": true, + "Default": {}, + "Elem": { + "Type": "SchemaElements", + "ElementsType": "TypeString" + } + }, + "name": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "quota": { + "Type": "TypeString", + "Optional": true, + "Computed": true, + "Default": {}, + "Elem": {} + } + }, + "cf_quota": { + "allow_paid_service_plans": { + "Type": "TypeBool", + "Required": true, + "Default": {}, + "Elem": {} + }, + "instance_memory": { + "Type": "TypeInt", + "Optional": true, + "Default": {}, + "Elem": {} + }, + "name": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "org": { + "Type": "TypeString", + "Optional": true, + "Default": {}, + "Elem": {} + }, + "total_app_instances": { + "Type": "TypeInt", + "Optional": true, + "Default": {}, + "Elem": {} + }, + "total_memory": { + "Type": "TypeInt", + "Required": true, + "Default": {}, + "Elem": {} + }, + "total_private_domains": { + "Type": "TypeInt", + "Optional": true, + "ConflictsWith": [ + "org" + ], + "Default": {}, + "Elem": {} + }, + "total_route_ports": { + "Type": "TypeInt", + "Optional": true, + "ConflictsWith": [ + "org" + ], + "Default": {}, + "Elem": {} + }, + "total_routes": { + "Type": "TypeInt", + "Required": true, + "Default": {}, + "Elem": {} + }, + "total_services": { + "Type": "TypeInt", + "Required": true, + "Default": {}, + "Elem": {} + } + }, + "cf_route": { + "domain": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "endpoint": { + "Type": "TypeString", + "Computed": true, + "Default": {}, + "Elem": {} + }, + "hostname": { + "Type": "TypeString", + "Optional": true, + "Default": {}, + "Elem": {} + }, + "path": { + "Type": "TypeString", + "Optional": true, + "ConflictsWith": [ + "port" + ], + "Default": {}, + "Elem": {} + }, + "port": { + "Type": "TypeInt", + "Optional": true, + "ConflictsWith": [ + "path", + "random_port" + ], + "Default": {}, + "Elem": {} + }, + "random_port": { + "Type": "TypeBool", + "Optional": true, + "ConflictsWith": [ + "path", + "port" + ], + "Default": {}, + "Elem": {} + }, + "space": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "target": { + "Type": "TypeSet", + "Optional": true, + "Default": {}, + "Elem": { + "Type": "SchemaInfo", + "Info": { + "app": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "mapping_id": { + "Type": "TypeString", + "Computed": true, + "Default": {}, + "Elem": {} + }, + "port": { + "Type": "TypeInt", + "Optional": true, + "Default": {}, + "Elem": {} + } + } + } + } + }, + "cf_service_access": { + "org": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "plan": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + } + }, + "cf_service_broker": { + "name": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "password": { + "Type": "TypeString", + "Optional": true, + "Default": {}, + "Elem": {} + }, + "service_plans": { + "Type": "TypeMap", + "Computed": true, + "Default": {}, + "Elem": {} + }, + "space": { + "Type": "TypeString", + "Optional": true, + "Default": {}, + "Elem": {} + }, + "url": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "username": { + "Type": "TypeString", + "Optional": true, + "Default": {}, + "Elem": {} + } + }, + "cf_service_instance": { + "json_params": { + "Type": "TypeString", + "Optional": true, + "Default": {}, + "Elem": {} + }, + "name": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "service_plan": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "space": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "tags": { + "Type": "TypeList", + "Optional": true, + "Default": {}, + "Elem": { + "Type": "SchemaElements", + "ElementsType": "TypeString" + } + } + }, + "cf_service_key": { + "credentials": { + "Type": "TypeMap", + "Computed": true, + "Default": {}, + "Elem": {} + }, + "name": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "params": { + "Type": "TypeMap", + "Optional": true, + "Default": {}, + "Elem": {} + }, + "service_instance": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + } + }, + "cf_space": { + "allow_ssh": { + "Type": "TypeBool", + "Optional": true, + "Default": {}, + "Elem": {} + }, + "asgs": { + "Type": "TypeSet", + "Optional": true, + "Default": {}, + "Elem": { + "Type": "SchemaElements", + "ElementsType": "TypeString" + } + }, + "auditors": { + "Type": "TypeSet", + "Optional": true, + "Default": {}, + "Elem": { + "Type": "SchemaElements", + "ElementsType": "TypeString" + } + }, + "developers": { + "Type": "TypeSet", + "Optional": true, + "Default": {}, + "Elem": { + "Type": "SchemaElements", + "ElementsType": "TypeString" + } + }, + "managers": { + "Type": "TypeSet", + "Optional": true, + "Default": {}, + "Elem": { + "Type": "SchemaElements", + "ElementsType": "TypeString" + } + }, + "name": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "org": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "quota": { + "Type": "TypeString", + "Optional": true, + "Default": {}, + "Elem": {} + } + }, + "cf_user": { + "email": { + "Type": "TypeString", + "Optional": true, + "Computed": true, + "Default": {}, + "Elem": {} + }, + "family_name": { + "Type": "TypeString", + "Optional": true, + "Default": {}, + "Elem": {} + }, + "given_name": { + "Type": "TypeString", + "Optional": true, + "Default": {}, + "Elem": {} + }, + "groups": { + "Type": "TypeSet", + "Optional": true, + "Default": {}, + "Elem": { + "Type": "SchemaElements", + "ElementsType": "TypeString" + } + }, + "name": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "origin": { + "Type": "TypeString", + "Optional": true, + "Default": {}, + "Elem": {} + }, + "password": { + "Type": "TypeString", + "Optional": true, + "Default": {}, + "Elem": {} + } + }, + "cf_user_provided_service": { + "credentials": { + "Type": "TypeMap", + "Optional": true, + "Default": {}, + "Elem": {} + }, + "name": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "routeServiceURL": { + "Type": "TypeString", + "Optional": true, + "Default": {}, + "Elem": {} + }, + "space": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "syslogDrainURL": { + "Type": "TypeString", + "Optional": true, + "Default": {}, + "Elem": {} + } + } + }, + "data-sources": { + "cf_asg": { + "name": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + } + }, + "cf_domain": { + "domain": { + "Type": "TypeString", + "Optional": true, + "Computed": true, + "ConflictsWith": [ + "name" + ], + "Default": {}, + "Elem": {} + }, + "name": { + "Type": "TypeString", + "Optional": true, + "Computed": true, + "Default": {}, + "Elem": {} + }, + "org": { + "Type": "TypeString", + "Computed": true, + "Default": {}, + "Elem": {} + }, + "sub_domain": { + "Type": "TypeString", + "Optional": true, + "ConflictsWith": [ + "name" + ], + "Default": {}, + "Elem": {} + } + }, + "cf_info": { + "api_endpoint": { + "Type": "TypeString", + "Computed": true, + "Default": {}, + "Elem": {} + }, + "api_version": { + "Type": "TypeString", + "Computed": true, + "Default": {}, + "Elem": {} + }, + "auth_endpoint": { + "Type": "TypeString", + "Computed": true, + "Default": {}, + "Elem": {} + }, + "doppler_endpoint": { + "Type": "TypeString", + "Computed": true, + "Default": {}, + "Elem": {} + }, + "logging_endpoint": { + "Type": "TypeString", + "Computed": true, + "Default": {}, + "Elem": {} + }, + "password": { + "Type": "TypeString", + "Computed": true, + "Default": {}, + "Elem": {} + }, + "routing_endpoint": { + "Type": "TypeString", + "Computed": true, + "Default": {}, + "Elem": {} + }, + "skip_ssl_validation": { + "Type": "TypeString", + "Computed": true, + "Default": {}, + "Elem": {} + }, + "uaa_endpoint": { + "Type": "TypeString", + "Computed": true, + "Default": {}, + "Elem": {} + }, + "user": { + "Type": "TypeString", + "Computed": true, + "Default": {}, + "Elem": {} + } + }, + "cf_org": { + "name": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + } + }, + "cf_quota": { + "name": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "org": { + "Type": "TypeString", + "Optional": true, + "Default": {}, + "Elem": {} + } + }, + "cf_router_group": { + "name": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "type": { + "Type": "TypeString", + "Computed": true, + "Default": {}, + "Elem": {} + } + }, + "cf_service": { + "name": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "service_plans": { + "Type": "TypeMap", + "Computed": true, + "Default": {}, + "Elem": {} + }, + "space": { + "Type": "TypeString", + "Optional": true, + "Default": {}, + "Elem": {} + } + }, + "cf_space": { + "name": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + }, + "org": { + "Type": "TypeString", + "Optional": true, + "Computed": true, + "ConflictsWith": [ + "org_name" + ], + "Default": {}, + "Elem": {} + }, + "org_name": { + "Type": "TypeString", + "Optional": true, + "Computed": true, + "ConflictsWith": [ + "org" + ], + "Default": {}, + "Elem": {} + }, + "quota": { + "Type": "TypeString", + "Computed": true, + "Default": {}, + "Elem": {} + } + }, + "cf_stack": { + "description": { + "Type": "TypeString", + "Computed": true, + "Default": {}, + "Elem": {} + }, + "name": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + } + }, + "cf_user": { + "name": { + "Type": "TypeString", + "Required": true, + "Default": {}, + "Elem": {} + } + } + } +} \ No newline at end of file diff --git a/generate-schema/generate-schema.go b/generate-schema/generate-schema.go new file mode 100644 index 000000000..1f98b11b3 --- /dev/null +++ b/generate-schema/generate-schema.go @@ -0,0 +1,173 @@ +package main + +import ( + "github.com/hashicorp/terraform/helper/schema" + tf "github.com/hashicorp/terraform/terraform" + "github.com/terraform-providers/terraform-provider-cf/cloudfoundry" + + "encoding/json" + "fmt" + "os" + "path/filepath" + "reflect" +) + +// ExportSchema should be called to export the structure +// of the provider. +func Export(p *schema.Provider) *ResourceProviderSchema { + result := new(ResourceProviderSchema) + + result.Name = "cf" + result.Type = "provider" + result.Version = "0.9.5" + result.Provider = schemaMap(p.Schema).Export() + result.Resources = make(map[string]SchemaInfo) + result.DataSources = make(map[string]SchemaInfo) + + for k, r := range p.ResourcesMap { + result.Resources[k] = ExportResource(r) + } + for k, ds := range p.DataSourcesMap { + result.DataSources[k] = ExportResource(ds) + } + + return result +} + +func ExportResource(r *schema.Resource) SchemaInfo { + return schemaMap(r.Schema).Export() +} + +// schemaMap is a wrapper that adds nice functions on top of schemas. +type schemaMap map[string]*schema.Schema + +// Export exports the format of this schema. +func (m schemaMap) Export() SchemaInfo { + result := make(SchemaInfo) + for k, v := range m { + item := export(v) + result[k] = item + } + return result +} + +func export(v *schema.Schema) SchemaDefinition { + item := SchemaDefinition{} + + item.Type = fmt.Sprintf("%s", v.Type) + item.Optional = v.Optional + item.Required = v.Required + item.Description = v.Description + item.InputDefault = v.InputDefault + item.Computed = v.Computed + item.MaxItems = v.MaxItems + item.MinItems = v.MinItems + item.PromoteSingle = v.PromoteSingle + item.ComputedWhen = v.ComputedWhen + item.ConflictsWith = v.ConflictsWith + item.Deprecated = v.Deprecated + item.Removed = v.Removed + + if v.Elem != nil { + item.Elem = exportValue(v.Elem, fmt.Sprintf("%T", v.Elem)) + } + + // TODO: Find better solution + if defValue, err := v.DefaultValue(); err == nil && defValue != nil && !reflect.DeepEqual(defValue, v.Default) { + item.Default = exportValue(defValue, fmt.Sprintf("%T", defValue)) + } + return item +} + +func exportValue(value interface{}, t string) SchemaElement { + s2, ok := value.(*schema.Schema) + if ok { + return SchemaElement{Type: "SchemaElements", ElementsType: fmt.Sprintf("%s", s2.Type)} + } + r2, ok := value.(*schema.Resource) + if ok { + return SchemaElement{Type: "SchemaInfo", Info: ExportResource(r2)} + } + return SchemaElement{Type: t, Value: fmt.Sprintf("%v", value)} +} + +func Generate(provider *schema.Provider, name string, outputPath string) { + outputFilePath := filepath.Join(outputPath, fmt.Sprintf("%s.json", name)) + + if err := DoGenerate(provider, name, outputFilePath); err != nil { + fmt.Fprintln(os.Stderr, "Error: ", err.Error()) + os.Exit(255) + } +} + +func DoGenerate(provider *schema.Provider, providerName string, outputFilePath string) error { + providerJson, err := json.MarshalIndent(Export(provider), "", " ") + + if err != nil { + return err + } + + file, err := os.Create(outputFilePath) + if err != nil { + return err + } + + defer file.Close() + + _, err = file.Write(providerJson) + if err != nil { + return err + } + + return file.Sync() +} + +type SchemaElement struct { + // One of ValueType or "SchemaElements" or "SchemaInfo" + Type string `json:",omitempty"` + // Set for simple types (from ValueType) + Value string `json:",omitempty"` + // Set if Type == "SchemaElements" + ElementsType string `json:",omitempty"` + // Set if Type == "SchemaInfo" + Info SchemaInfo `json:",omitempty"` +} + +type SchemaDefinition struct { + Type string `json:",omitempty"` + Optional bool `json:",omitempty"` + Required bool `json:",omitempty"` + Description string `json:",omitempty"` + InputDefault string `json:",omitempty"` + Computed bool `json:",omitempty"` + MaxItems int `json:",omitempty"` + MinItems int `json:",omitempty"` + PromoteSingle bool `json:",omitempty"` + + ComputedWhen []string `json:",omitempty"` + ConflictsWith []string `json:",omitempty"` + + Deprecated string `json:",omitempty"` + Removed string `json:",omitempty"` + + Default SchemaElement `json:",omitempty"` + Elem SchemaElement `json:",omitempty"` +} + +type SchemaInfo map[string]SchemaDefinition + +// ResourceProviderSchema +type ResourceProviderSchema struct { + Name string `json:"name"` + Type string `json:"type"` + Version string `json:"version"` + Provider SchemaInfo `json:"provider"` + Resources map[string]SchemaInfo `json:"resources"` + DataSources map[string]SchemaInfo `json:"data-sources"` +} + +func main() { + var provider tf.ResourceProvider + provider = cloudfoundry.Provider() + Generate(provider.(*schema.Provider), "cf", "/home/guillaume/public-code/intellij-hcl/schemas-extractor/schemas") +} From 485fd5ebf7bd9971395f4cb191bfe35d667e85de Mon Sep 17 00:00:00 2001 From: Mevan Samaratunga Date: Tue, 9 Jan 2018 20:37:00 +0100 Subject: [PATCH 2/6] move tfacc environment variable file decryption to build script --- .travis.yml | 4 +--- scripts/build.sh | 3 +++ 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8070c2eab..68f94b033 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,10 +4,8 @@ language: go go: - 1.8.x go_import_path: github.com/terraform-providers/terraform-provider-cf -before_install: -- openssl aes-256-cbc -K $encrypted_22350934ad09_key -iv $encrypted_22350934ad09_iv - -in .test_env/tfacc_env.enc -out .test_env/tfacc_env -d install: +- sudo apt-get update - sudo apt-get install jq - pip install --upgrade --user awscli - bash scripts/gogetcookie.sh diff --git a/scripts/build.sh b/scripts/build.sh index 185896efa..348615baf 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -58,6 +58,9 @@ make testacc EOF else + openssl aes-256-cbc -K $encrypted_22350934ad09_key -iv $encrypted_22350934ad09_iv \ + -in .test_env/tfacc_env.enc -out .test_env/tfacc_env -d + source .test_env/tfacc_env make testacc fi From 79a0bae103c5d03fac7f0d8987bb79412773deb2 Mon Sep 17 00:00:00 2001 From: Mevan Samaratunga Date: Wed, 10 Jan 2018 22:26:25 +0100 Subject: [PATCH 3/6] removed redundant code --- cloudfoundry/data_source_cf_service_test.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/cloudfoundry/data_source_cf_service_test.go b/cloudfoundry/data_source_cf_service_test.go index 7fb70819c..6a7e6dafb 100644 --- a/cloudfoundry/data_source_cf_service_test.go +++ b/cloudfoundry/data_source_cf_service_test.go @@ -71,10 +71,8 @@ func checkDataSourceServiceExists(resource string) resource.TestCheckFunc { if err != nil { return err } - if err := assertSame(id, service.GUID); err != nil { - return err - } + err = assertSame(id, service.GUID) - return nil + return err } } From 0d43ac6c11aa59b0daa9bd9d066ec247e0cbf1c3 Mon Sep 17 00:00:00 2001 From: Mevan Samaratunga Date: Wed, 10 Jan 2018 22:27:09 +0100 Subject: [PATCH 4/6] fixed https://github.com/mevansam/terraform-provider-cf/issues/7 --- cloudfoundry/cfapi/service_manager.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cloudfoundry/cfapi/service_manager.go b/cloudfoundry/cfapi/service_manager.go index 30b967be8..110622cf4 100644 --- a/cloudfoundry/cfapi/service_manager.go +++ b/cloudfoundry/cfapi/service_manager.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "net/url" + "strings" "code.cloudfoundry.org/cli/cf/api" "code.cloudfoundry.org/cli/cf/api/resources" @@ -719,7 +720,7 @@ func (sm *ServiceManager) GetServicePlans(serviceID string) (servicePlans map[st resources.ServicePlanResource{}, func(resource interface{}) bool { if sp, ok := resource.(resources.ServicePlanResource); ok { - servicePlans[sp.Entity.Name] = sp.Metadata.GUID + servicePlans[strings.Replace(sp.Entity.Name, ".", "_", -1)] = sp.Metadata.GUID } return true }) From e944d99db4b0fcc0a041c86d7cbc1d7c611fbf40 Mon Sep 17 00:00:00 2001 From: Mevan Samaratunga Date: Wed, 17 Jan 2018 21:32:22 +0100 Subject: [PATCH 5/6] added list attribute to enable associating staging asgs with a space --- cloudfoundry/cfapi/space_manager.go | 46 ++++++++++++++--- cloudfoundry/resource_cf_space.go | 19 +++++++ cloudfoundry/resource_cf_space_test.go | 69 +++++++++++++++++++++++++- website/docs/r/asg.html.markdown | 4 +- website/docs/r/space.html.markdown | 15 +++--- 5 files changed, 136 insertions(+), 17 deletions(-) diff --git a/cloudfoundry/cfapi/space_manager.go b/cloudfoundry/cfapi/space_manager.go index 1bd9019b0..ec2376363 100644 --- a/cloudfoundry/cfapi/space_manager.go +++ b/cloudfoundry/cfapi/space_manager.go @@ -183,6 +183,12 @@ func (sm *SpaceManager) UpdateSpace(space CCSpace, asgs []interface{}) (err erro return } +// DeleteSpace - +func (sm *SpaceManager) DeleteSpace(id string) (err error) { + err = sm.ccGateway.DeleteResource(sm.apiEndpoint, fmt.Sprintf("/v2/spaces/%s", id)) + return +} + // AddUser - func (sm *SpaceManager) AddUser(spaceID string, userID string, role SpaceRole) (err error) { @@ -212,8 +218,25 @@ func (sm *SpaceManager) ListUsers(spaceID string, role SpaceRole) (userIDs []int return } -// ListASGs - -func (sm *SpaceManager) ListASGs(spaceID string) (asgIDs []interface{}, err error) { +// AddStagingASG - +func (sm *SpaceManager) AddStagingASG(spaceID string, asgID string) (err error) { + + err = sm.ccGateway.UpdateResource(sm.apiEndpoint, + fmt.Sprintf("/v2/spaces/%s/staging_security_groups/%s", spaceID, asgID), + strings.NewReader("")) + return +} + +// RemoveStagingASG - +func (sm *SpaceManager) RemoveStagingASG(spaceID string, asgID string) (err error) { + + err = sm.ccGateway.DeleteResource(sm.apiEndpoint, + fmt.Sprintf("/v2/spaces/%s/staging_security_groups/%s", spaceID, asgID)) + return +} + +// ListStagingASGs - +func (sm *SpaceManager) ListStagingASGs(spaceID string) (asgIDs []interface{}, err error) { asgList := struct { Resources []struct { @@ -222,15 +245,26 @@ func (sm *SpaceManager) ListASGs(spaceID string) (asgIDs []interface{}, err erro }{} err = sm.ccGateway.GetResource( - fmt.Sprintf("%s/v2/spaces/%s/security_groups", sm.apiEndpoint, spaceID), &asgList) + fmt.Sprintf("%s/v2/spaces/%s/staging_security_groups", sm.apiEndpoint, spaceID), &asgList) for _, r := range asgList.Resources { asgIDs = append(asgIDs, r.Metadata.GUID) } return } -// DeleteSpace - -func (sm *SpaceManager) DeleteSpace(id string) (err error) { - err = sm.ccGateway.DeleteResource(sm.apiEndpoint, fmt.Sprintf("/v2/spaces/%s", id)) +// ListASGs - +func (sm *SpaceManager) ListASGs(spaceID string) (asgIDs []interface{}, err error) { + + asgList := struct { + Resources []struct { + Metadata resources.Metadata `json:"metadata"` + } `json:"resources"` + }{} + + err = sm.ccGateway.GetResource( + fmt.Sprintf("%s/v2/spaces/%s/security_groups", sm.apiEndpoint, spaceID), &asgList) + for _, r := range asgList.Resources { + asgIDs = append(asgIDs, r.Metadata.GUID) + } return } diff --git a/cloudfoundry/resource_cf_space.go b/cloudfoundry/resource_cf_space.go index 241195538..11e884867 100644 --- a/cloudfoundry/resource_cf_space.go +++ b/cloudfoundry/resource_cf_space.go @@ -41,6 +41,12 @@ func resourceSpace() *schema.Resource { Elem: &schema.Schema{Type: schema.TypeString}, Set: resourceStringHash, }, + "staging_asgs": &schema.Schema{ + Type: schema.TypeSet, + Optional: true, + Elem: &schema.Schema{Type: schema.TypeString}, + Set: resourceStringHash, + }, "managers": &schema.Schema{ Type: schema.TypeSet, Optional: true, @@ -198,6 +204,19 @@ func resourceSpaceUpdate(d *schema.ResourceData, meta interface{}) (err error) { } } + old, new := d.GetChange("staging_asgs") + remove, add := getListChanges(old, new) + for _, asgID := range remove { + if err = sm.RemoveStagingASG(spaceID, asgID); err != nil { + return + } + } + for _, asgID := range add { + if err = sm.AddStagingASG(spaceID, asgID); err != nil { + return + } + } + usersRemoved := make(map[string]bool) usersAdded := make(map[string]bool) diff --git a/cloudfoundry/resource_cf_space_test.go b/cloudfoundry/resource_cf_space_test.go index 7d014cfe3..9399da07b 100644 --- a/cloudfoundry/resource_cf_space_test.go +++ b/cloudfoundry/resource_cf_space_test.go @@ -24,6 +24,27 @@ resource "cf_asg" "svc" { destination = "192.168.100.0/24" } } +resource "cf_asg" "stg1" { + name = "app-services" + rule { + protocol = "all" + destination = "192.168.101.0/24" + } +} +resource "cf_asg" "stg2" { + name = "app-services" + rule { + protocol = "all" + destination = "192.168.102.0/24" + } +} +resource "cf_asg" "stg3" { + name = "app-services" + rule { + protocol = "all" + destination = "192.168.103.0/24" + } +} resource "cf_user" "tl" { name = "teamlead@acme.com" password = "password" @@ -63,6 +84,7 @@ resource "cf_space" "space1" { org = "${cf_org.org1.id}" quota = "${cf_quota.dev.id}" asgs = [ "${cf_asg.svc.id}" ] + staging_asgs = [ "${cf_asg.stg1.id}", "${cf_asg.stg2.id}" ] managers = [ "${cf_user.tl.id}" ] @@ -91,6 +113,27 @@ resource "cf_asg" "svc" { destination = "192.168.100.0/24" } } +resource "cf_asg" "stg1" { + name = "app-services" + rule { + protocol = "all" + destination = "192.168.101.0/24" + } +} +resource "cf_asg" "stg2" { + name = "app-services" + rule { + protocol = "all" + destination = "192.168.102.0/24" + } +} +resource "cf_asg" "stg3" { + name = "app-services" + rule { + protocol = "all" + destination = "192.168.103.0/24" + } +} resource "cf_user" "tl" { name = "teamlead@acme.com" password = "password" @@ -130,6 +173,7 @@ resource "cf_space" "space1" { org = "${cf_org.org1.id}" quota = "${cf_quota.dev.id}" asgs = [ "${cf_asg.svc.id}" ] + staging_asgs = [ "${cf_asg.stg2.id}", "${cf_asg.stg3.id}" ] managers = [ "${cf_user.tl.id}" ] @@ -215,8 +259,8 @@ func testAccCheckSpaceExists(resource string, refUserRemoved *string) resource.T var ( space cfapi.CCSpace - runningAsgs []string - spaceAsgs, asgs []interface{} + runningAsgs, stagingAsgs []string + spaceAsgs []interface{} managers, developers, auditors []interface{} ) @@ -247,6 +291,7 @@ func testAccCheckSpaceExists(resource string, refUserRemoved *string) resource.T if spaceAsgs, err = sm.ListASGs(id); err != nil { return } + asgs := []interface{}{} for _, a := range spaceAsgs { if !isStringInList(runningAsgs, a.(string)) { asgs = append(asgs, a) @@ -260,6 +305,26 @@ func testAccCheckSpaceExists(resource string, refUserRemoved *string) resource.T return err } + if stagingAsgs, err = session.ASGManager().Staging(); err != nil { + return err + } + if spaceAsgs, err = sm.ListStagingASGs(id); err != nil { + return + } + asgs = []interface{}{} + for _, a := range spaceAsgs { + if !isStringInList(stagingAsgs, a.(string)) { + asgs = append(asgs, a) + } + } + session.Log.DebugMessage( + "retrieved staging asgs of space identified resource '%s': %# v", + resource, asgs) + + if err := assertSetEquals(attributes, "staging_asgs", asgs); err != nil { + return err + } + if managers, err = sm.ListUsers(id, cfapi.SpaceRoleManager); err != nil { return } diff --git a/website/docs/r/asg.html.markdown b/website/docs/r/asg.html.markdown index 63881980b..18a12bf38 100644 --- a/website/docs/r/asg.html.markdown +++ b/website/docs/r/asg.html.markdown @@ -25,13 +25,13 @@ resource "cf_asg" "messaging" { protocol = "tcp" destination = "192.168.1.100" ports = "5671-5672,61613-61614,1883,8883" - log = true + log = true } rule { protocol = "tcp" destination = "192.168.1.101" ports = "5671-5672,61613-61614,1883,8883" - log = true + log = true } } ``` diff --git a/website/docs/r/space.html.markdown b/website/docs/r/space.html.markdown index f446b0519..4974786a8 100644 --- a/website/docs/r/space.html.markdown +++ b/website/docs/r/space.html.markdown @@ -40,14 +40,15 @@ resource "cf_space" "s1" { The following arguments are supported: -* `name` - (Required) The name of the Space in Cloud Foundry -* `org` - (Required) The ID of the [Org](/docs/providers/cloudfoundry/r/org.html) within which to create the space -* `quota` - (Optional) The ID of the Space [quota](/docs/providers/cloudfoundry/r/quota.html) or plan defined for the owning Org +* `name` - (Required) The name of the Space in Cloud Foundry. +* `org` - (Required) The ID of the [Org](/docs/providers/cloudfoundry/r/org.html) within which to create the space. +* `quota` - (Optional) The ID of the Space [quota](/docs/providers/cloudfoundry/r/quota.html) or plan defined for the owning Org. * `allow_ssh` - (Optional) Allows SSH to application containers via the [CF CLI](https://github.com/cloudfoundry/cli) -* `asgs` - (Optional) List of [application security groups](/docs/providers/cloudfoundry/r/asg.html) -* `managers` - (Optional) List of users to assign [SpaceManager](https://docs.cloudfoundry.org/concepts/roles.html#roles) role to -* `developers` - (Optional) List of users to assign [SpaceDeveloper](https://docs.cloudfoundry.org/concepts/roles.html#roles) role to -* `auditors` - (Optional) List of users to assign [SpaceAuditor](https://docs.cloudfoundry.org/concepts/roles.html#roles) role to +* `asgs` - (Optional) List of running [application security groups](/docs/providers/cloudfoundry/r/asg.html) to apply to applications running within this space. +* `staging_asgs` - (Optional) List of staging [application security groups](/docs/providers/cloudfoundry/r/asg.html) to apply to applications being staged for this space. +* `managers` - (Optional) List of users to assign [SpaceManager](https://docs.cloudfoundry.org/concepts/roles.html#roles) role to. +* `developers` - (Optional) List of users to assign [SpaceDeveloper](https://docs.cloudfoundry.org/concepts/roles.html#roles) role to. +* `auditors` - (Optional) List of users to assign [SpaceAuditor](https://docs.cloudfoundry.org/concepts/roles.html#roles) role to. ## Attributes Reference From a4dd617190ee2de391e54d592a8b5357fde12a33 Mon Sep 17 00:00:00 2001 From: Mevan Samaratunga Date: Wed, 17 Jan 2018 23:32:56 +0100 Subject: [PATCH 6/6] fixed https://github.com/mevansam/terraform-provider-cf/issues/11 normalize returned credential map so all values are correctly exposed by the Terraform sub-system --- cloudfoundry/resource_cf_service_key.go | 4 +- cloudfoundry/utils_map.go | 184 ++++++++++++++++++++++++ 2 files changed, 186 insertions(+), 2 deletions(-) create mode 100644 cloudfoundry/utils_map.go diff --git a/cloudfoundry/resource_cf_service_key.go b/cloudfoundry/resource_cf_service_key.go index 7a6ffe269..988fccf82 100644 --- a/cloudfoundry/resource_cf_service_key.go +++ b/cloudfoundry/resource_cf_service_key.go @@ -59,7 +59,7 @@ func resourceServiceKeyCreate(d *schema.ResourceData, meta interface{}) (err err } session.Log.DebugMessage("Created Service Key: %# v", serviceKey) - d.Set("credentials", serviceKey.Credentials) + d.Set("credentials", normalizeMap(serviceKey.Credentials, make(map[string]interface{}), "", "_")) d.SetId(serviceKey.ID) return } @@ -81,7 +81,7 @@ func resourceServiceKeyRead(d *schema.ResourceData, meta interface{}) (err error } d.Set("name", serviceKey.Name) d.Set("service_instance", serviceKey.ServiceGUID) - d.Set("credentials", serviceKey.Credentials) + d.Set("credentials", normalizeMap(serviceKey.Credentials, make(map[string]interface{}), "", "_")) session.Log.DebugMessage("Read Service Instance : %# v", serviceKey) return diff --git a/cloudfoundry/utils_map.go b/cloudfoundry/utils_map.go new file mode 100644 index 000000000..cbcd3c981 --- /dev/null +++ b/cloudfoundry/utils_map.go @@ -0,0 +1,184 @@ +package cloudfoundry + +import ( + "fmt" + "reflect" + "strconv" +) + +// normalizeMap - +func normalizeMap(in interface{}, outMap map[string]interface{}, key, delim string) map[string]interface{} { + + rt := reflect.TypeOf(in) + switch rt.Kind() { + + case reflect.String: + outMap[key] = in.(string) + + case reflect.Bool: + outMap[key] = strconv.FormatBool(in.(bool)) + + case reflect.Int: + outMap[key] = strconv.FormatInt(int64(in.(int)), 10) + case reflect.Int8: + outMap[key] = strconv.FormatInt(int64(in.(int8)), 10) + case reflect.Int16: + outMap[key] = strconv.FormatInt(int64(in.(int16)), 10) + case reflect.Int32: + outMap[key] = strconv.FormatInt(int64(in.(int32)), 10) + case reflect.Int64: + outMap[key] = strconv.FormatInt(in.(int64), 10) + + case reflect.Uint: + outMap[key] = strconv.FormatUint(uint64(in.(uint)), 10) + case reflect.Uint8: + outMap[key] = strconv.FormatUint(uint64(in.(uint8)), 10) + case reflect.Uint16: + outMap[key] = strconv.FormatUint(uint64(in.(uint16)), 10) + case reflect.Uint32: + outMap[key] = strconv.FormatUint(uint64(in.(uint32)), 10) + case reflect.Uint64: + outMap[key] = strconv.FormatUint(in.(uint64), 10) + + case reflect.Float32: + outMap[key] = strconv.FormatFloat(float64(in.(float32)), 'g', -1, 32) + case reflect.Float64: + outMap[key] = strconv.FormatFloat(in.(float64), 'g', -1, 64) + + case reflect.Array, reflect.Slice: + + switch rt.Elem().Kind() { + case reflect.String: + for i, v := range in.([]string) { + normalizeMap(v, outMap, fmt.Sprintf("%s%s%d", key, delim, i), delim) + } + case reflect.Bool: + for i, v := range in.([]bool) { + normalizeMap(v, outMap, fmt.Sprintf("%s%s%d", key, delim, i), delim) + } + case reflect.Int: + for i, v := range in.([]int) { + normalizeMap(v, outMap, fmt.Sprintf("%s%s%d", key, delim, i), delim) + } + case reflect.Int8: + for i, v := range in.([]int8) { + normalizeMap(v, outMap, fmt.Sprintf("%s%s%d", key, delim, i), delim) + } + case reflect.Int16: + for i, v := range in.([]string) { + normalizeMap(v, outMap, fmt.Sprintf("%s%s%d", key, delim, i), delim) + } + case reflect.Int32: + for i, v := range in.([]int32) { + normalizeMap(v, outMap, fmt.Sprintf("%s%s%d", key, delim, i), delim) + } + case reflect.Int64: + for i, v := range in.([]int64) { + normalizeMap(v, outMap, fmt.Sprintf("%s%s%d", key, delim, i), delim) + } + case reflect.Uint: + for i, v := range in.([]uint) { + normalizeMap(v, outMap, fmt.Sprintf("%s%s%d", key, delim, i), delim) + } + case reflect.Uint8: + for i, v := range in.([]uint8) { + normalizeMap(v, outMap, fmt.Sprintf("%s%s%d", key, delim, i), delim) + } + case reflect.Uint16: + for i, v := range in.([]uint16) { + normalizeMap(v, outMap, fmt.Sprintf("%s%s%d", key, delim, i), delim) + } + case reflect.Uint32: + for i, v := range in.([]uint32) { + normalizeMap(v, outMap, fmt.Sprintf("%s%s%d", key, delim, i), delim) + } + case reflect.Uint64: + for i, v := range in.([]uint64) { + normalizeMap(v, outMap, fmt.Sprintf("%s%s%d", key, delim, i), delim) + } + case reflect.Float32: + for i, v := range in.([]float32) { + normalizeMap(v, outMap, fmt.Sprintf("%s%s%d", key, delim, i), delim) + } + case reflect.Float64: + for i, v := range in.([]float64) { + normalizeMap(v, outMap, fmt.Sprintf("%s%s%d", key, delim, i), delim) + } + default: + for i, v := range in.([]interface{}) { + normalizeMap(v, outMap, fmt.Sprintf("%s%s%d", key, delim, i), delim) + } + } + + case reflect.Map: + + if len(key) != 0 { + key = key + delim + } + + switch rt.Elem().Kind() { + case reflect.String: + for k, v := range in.(map[string]string) { + normalizeMap(v, outMap, key+k, delim) + } + case reflect.Bool: + for k, v := range in.(map[string]bool) { + normalizeMap(v, outMap, key+k, delim) + } + case reflect.Int: + for k, v := range in.(map[string]int) { + normalizeMap(v, outMap, key+k, delim) + } + case reflect.Int8: + for k, v := range in.(map[string]int8) { + normalizeMap(v, outMap, key+k, delim) + } + case reflect.Int16: + for k, v := range in.(map[string]string) { + normalizeMap(v, outMap, key+k, delim) + } + case reflect.Int32: + for k, v := range in.(map[string]int32) { + normalizeMap(v, outMap, key+k, delim) + } + case reflect.Int64: + for k, v := range in.(map[string]int64) { + normalizeMap(v, outMap, key+k, delim) + } + case reflect.Uint: + for k, v := range in.(map[string]uint) { + normalizeMap(v, outMap, key+k, delim) + } + case reflect.Uint8: + for k, v := range in.(map[string]uint8) { + normalizeMap(v, outMap, key+k, delim) + } + case reflect.Uint16: + for k, v := range in.(map[string]uint16) { + normalizeMap(v, outMap, key+k, delim) + } + case reflect.Uint32: + for k, v := range in.(map[string]uint32) { + normalizeMap(v, outMap, key+k, delim) + } + case reflect.Uint64: + for k, v := range in.(map[string]uint64) { + normalizeMap(v, outMap, key+k, delim) + } + case reflect.Float32: + for k, v := range in.(map[string]float32) { + normalizeMap(v, outMap, key+k, delim) + } + case reflect.Float64: + for k, v := range in.(map[string]float64) { + normalizeMap(v, outMap, key+k, delim) + } + default: + for k, v := range in.(map[string]interface{}) { + normalizeMap(v, outMap, key+k, delim) + } + } + } + + return outMap +}