Skip to content

Commit 7396ce8

Browse files
authored
Merge branch 'master' into datadog-api-spec/generated/4516
2 parents bc7d451 + 0be2cf7 commit 7396ce8

27 files changed

+2423
-3
lines changed

.generator/schemas/v2/openapi.yaml

Lines changed: 422 additions & 0 deletions
Large diffs are not rendered by default.

.generator/src/generator/formatter.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -275,6 +275,16 @@ def format_data_with_schema_list(
275275
return f"[\n{parameters}]"
276276

277277

278+
def _is_valid_ruby_symbol(key):
279+
"""Check if a key can be used as a Ruby symbol without quotes."""
280+
if not key:
281+
return False
282+
# Ruby symbols can start with letter or underscore, contain alphanumeric and underscores
283+
if not (key[0].isalpha() or key[0] == '_'):
284+
return False
285+
return all(c.isalnum() or c == '_' for c in key)
286+
287+
278288
@format_data_with_schema.register(dict)
279289
def format_data_with_schema_dict(
280290
data,
@@ -318,7 +328,11 @@ def format_data_with_schema_dict(
318328
name_prefix=name_prefix,
319329
replace_values=replace_values,
320330
)
321-
parameters += f"{k}: {value}, "
331+
# Use hash rocket syntax for keys with special characters
332+
if _is_valid_ruby_symbol(k):
333+
parameters += f"{k}: {value}, "
334+
else:
335+
parameters += f'"{k}" => {value}, '
322336
if not has_properties:
323337
name = None
324338

.generator/src/generator/templates/api.j2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,11 @@ module {{ module_name }}::{{ version|upper }}
3636
#
3737
{%- endif %}
3838
{%- for name, parameter in operation|parameters if parameter.required %}
39-
# @param {{ name|attribute_name }} [{{ get_type_for_parameter(parameter) }}] {{ parameter.get("description", "").replace('\n', ' ') }}
39+
# @param {{ name|attribute_name }} [{{ get_type_for_parameter(parameter) }}] {{ (parameter.get("description") or "").replace('\n', ' ') }}
4040
{%- endfor %}
4141
# @param opts [Hash] the optional parameters
4242
{%- for name, parameter in operation|parameters if not parameter.required %}
43-
# @option opts [{{ get_type_for_parameter(parameter) }}] :{{ name|attribute_name }} {{ parameter.get("description", "").replace('\n', ' ') }}{% if "default" in parameter%} (default to {{ parameter.default|json }}) {% endif %}
43+
# @option opts [{{ get_type_for_parameter(parameter) }}] :{{ name|attribute_name }} {{ (parameter.get("description") or "").replace('\n', ' ') }}{% if "default" in parameter%} (default to {{ parameter.default|json }}) {% endif %}
4444
{%- endfor %}
4545
# @return [Array<({% if returnType %}{{ returnType }}{% else %}nil{% endif %}, Integer, Hash)>] {% if returnType %}{{ returnType }} data{% else %}nil{% endif %}, response status code and response headers
4646
def {{ operation.operationId|snake_case }}_with_http_info({% for name, parameter in operation|parameters if parameter.required %}{{ name|attribute_name }}, {% endfor %}opts = {})

.generator/tests/test_formatter.rb

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
#!/usr/bin/env ruby
2+
3+
def assert(condition, message = "Assertion failed")
4+
raise message unless condition
5+
print "."
6+
end
7+
8+
def assert_equal(expected, actual, message = nil)
9+
msg = message || "Expected #{expected.inspect}, got #{actual.inspect}"
10+
raise msg unless expected == actual
11+
print "."
12+
end
13+
14+
def assert_includes(collection, item, message = nil)
15+
msg = message || "Expected #{collection.inspect} to include #{item.inspect}"
16+
raise msg unless collection.include?(item)
17+
print "."
18+
end
19+
20+
test_cases = [
21+
['valid_key', true],
22+
['_valid_key', true],
23+
['ValidKey123', true],
24+
['key123', true],
25+
['key.with.dots', false],
26+
['123invalid', false],
27+
['.starts_with_dot', false],
28+
['', false],
29+
['key-with-dash', false],
30+
['key with space', false],
31+
['key@special', false]
32+
]
33+
34+
test_cases.each do |key, expected|
35+
begin
36+
eval("{#{key}: 'value'}")
37+
assert(expected, "Expected '#{key}' to fail but it succeeded")
38+
rescue SyntaxError
39+
assert(!expected, "Expected '#{key}' to succeed but it failed")
40+
end
41+
end
42+
43+
hash = {
44+
"ocsf.activity_name" => 'Other',
45+
"ocsf.activity_id" => '99'
46+
}
47+
48+
assert(hash.is_a?(Hash))
49+
assert_equal('Other', hash["ocsf.activity_name"])
50+
assert_equal('99', hash["ocsf.activity_id"])
51+
assert_includes(hash.inspect, '"ocsf.activity_name"=>"Other"')
52+
assert_includes(hash.inspect, '"ocsf.activity_id"=>"99"')
53+
54+
hash = {
55+
"ocsf.activity_name" => ['eventName']
56+
}
57+
58+
assert(hash.is_a?(Hash))
59+
assert_equal(['eventName'], hash["ocsf.activity_name"])
60+
assert_includes(hash.inspect, '"ocsf.activity_name"=>["eventName"]')
61+
62+
hash = {
63+
normal_key: 'value1',
64+
another_key: 'value2'
65+
}
66+
67+
assert(hash.is_a?(Hash))
68+
assert_equal('value1', hash[:normal_key])
69+
assert_equal('value2', hash[:another_key])
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Cancel a deployment returns "Deployment successfully canceled." response
2+
3+
require "datadog_api_client"
4+
DatadogAPIClient.configure do |config|
5+
config.unstable_operations["v2.cancel_fleet_deployment".to_sym] = true
6+
end
7+
api_instance = DatadogAPIClient::V2::FleetAutomationAPI.new
8+
api_instance.cancel_fleet_deployment("deployment_id")
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Create a deployment returns "CREATED" response
2+
3+
require "datadog_api_client"
4+
DatadogAPIClient.configure do |config|
5+
config.unstable_operations["v2.create_fleet_deployment_configure".to_sym] = true
6+
end
7+
api_instance = DatadogAPIClient::V2::FleetAutomationAPI.new
8+
9+
body = DatadogAPIClient::V2::FleetDeploymentConfigureCreateRequest.new({
10+
data: DatadogAPIClient::V2::FleetDeploymentConfigureCreate.new({
11+
attributes: DatadogAPIClient::V2::FleetDeploymentConfigureAttributes.new({
12+
config_operations: [
13+
DatadogAPIClient::V2::FleetDeploymentOperation.new({
14+
file_op: DatadogAPIClient::V2::FleetDeploymentFileOp::MERGE_PATCH,
15+
file_path: "/datadog.yaml",
16+
patch: {
17+
"apm_config": "{'enabled': True}", "log_level": "debug", "logs_enabled": "True",
18+
},
19+
}),
20+
],
21+
filter_query: "env:prod AND service:web",
22+
}),
23+
type: DatadogAPIClient::V2::FleetDeploymentResourceType::DEPLOYMENT,
24+
}),
25+
})
26+
p api_instance.create_fleet_deployment_configure(body)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Get a deployment by ID returns "OK" response
2+
3+
require "datadog_api_client"
4+
DatadogAPIClient.configure do |config|
5+
config.unstable_operations["v2.get_fleet_deployment".to_sym] = true
6+
end
7+
api_instance = DatadogAPIClient::V2::FleetAutomationAPI.new
8+
9+
# there is a valid "deployment" in the system
10+
DEPLOYMENT_ID = ENV["DEPLOYMENT_ID"]
11+
p api_instance.get_fleet_deployment(DEPLOYMENT_ID)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# List all deployments returns "OK" response
2+
3+
require "datadog_api_client"
4+
DatadogAPIClient.configure do |config|
5+
config.unstable_operations["v2.list_fleet_deployments".to_sym] = true
6+
end
7+
api_instance = DatadogAPIClient::V2::FleetAutomationAPI.new
8+
p api_instance.list_fleet_deployments()

features/scenarios_model_mapping.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -838,6 +838,19 @@
838838
"user_handle" => "String",
839839
"body" => "User",
840840
},
841+
"v2.ListFleetDeployments" => {
842+
"page_size" => "Integer",
843+
"page_offset" => "Integer",
844+
},
845+
"v2.CreateFleetDeploymentConfigure" => {
846+
"body" => "FleetDeploymentConfigureCreateRequest",
847+
},
848+
"v2.GetFleetDeployment" => {
849+
"deployment_id" => "String",
850+
},
851+
"v2.CancelFleetDeployment" => {
852+
"deployment_id" => "String",
853+
},
841854
"v2.CreateDatastore" => {
842855
"body" => "CreateAppsDatastoreRequest",
843856
},
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
@endpoint(fleet-automation) @endpoint(fleet-automation-v2)
2+
Feature: Fleet Automation
3+
Manage automated deployments across your fleet of hosts. Use these
4+
endpoints to create, retrieve, and cancel deployments that apply
5+
configuration changes to multiple hosts at once.
6+
7+
Background:
8+
Given a valid "apiKeyAuth" key in the system
9+
And a valid "appKeyAuth" key in the system
10+
And an instance of "FleetAutomation" API
11+
12+
@generated @skip @team:DataDog/fleet-automation
13+
Scenario: Cancel a deployment returns "Bad Request" response
14+
Given operation "CancelFleetDeployment" enabled
15+
And new "CancelFleetDeployment" request
16+
And request contains "deployment_id" parameter from "REPLACE.ME"
17+
When the request is sent
18+
Then the response status is 400 Bad Request
19+
20+
@generated @skip @team:DataDog/fleet-automation
21+
Scenario: Cancel a deployment returns "Deployment successfully canceled." response
22+
Given operation "CancelFleetDeployment" enabled
23+
And new "CancelFleetDeployment" request
24+
And request contains "deployment_id" parameter from "REPLACE.ME"
25+
When the request is sent
26+
Then the response status is 204 Deployment successfully canceled.
27+
28+
@generated @skip @team:DataDog/fleet-automation
29+
Scenario: Cancel a deployment returns "Not Found" response
30+
Given operation "CancelFleetDeployment" enabled
31+
And new "CancelFleetDeployment" request
32+
And request contains "deployment_id" parameter from "REPLACE.ME"
33+
When the request is sent
34+
Then the response status is 404 Not Found
35+
36+
@generated @skip @team:DataDog/fleet-automation
37+
Scenario: Create a deployment returns "Bad Request" response
38+
Given operation "CreateFleetDeploymentConfigure" enabled
39+
And new "CreateFleetDeploymentConfigure" request
40+
And body with value {"data": {"attributes": {"config_operations": [{"file_op": "merge-patch", "file_path": "/datadog.yaml", "patch": {"apm_config": {"enabled": true}, "log_level": "debug", "logs_enabled": true}}], "filter_query": "env:prod AND service:web"}, "type": "deployment"}}
41+
When the request is sent
42+
Then the response status is 400 Bad Request
43+
44+
@generated @skip @team:DataDog/fleet-automation
45+
Scenario: Create a deployment returns "CREATED" response
46+
Given operation "CreateFleetDeploymentConfigure" enabled
47+
And new "CreateFleetDeploymentConfigure" request
48+
And body with value {"data": {"attributes": {"config_operations": [{"file_op": "merge-patch", "file_path": "/datadog.yaml", "patch": {"apm_config": {"enabled": true}, "log_level": "debug", "logs_enabled": true}}], "filter_query": "env:prod AND service:web"}, "type": "deployment"}}
49+
When the request is sent
50+
Then the response status is 201 CREATED
51+
52+
@generated @skip @team:DataDog/fleet-automation
53+
Scenario: Get a deployment by ID returns "Bad Request" response
54+
Given operation "GetFleetDeployment" enabled
55+
And new "GetFleetDeployment" request
56+
And request contains "deployment_id" parameter from "REPLACE.ME"
57+
When the request is sent
58+
Then the response status is 400 Bad Request
59+
60+
@generated @skip @team:DataDog/fleet-automation
61+
Scenario: Get a deployment by ID returns "Not Found" response
62+
Given operation "GetFleetDeployment" enabled
63+
And new "GetFleetDeployment" request
64+
And request contains "deployment_id" parameter from "REPLACE.ME"
65+
When the request is sent
66+
Then the response status is 404 Not Found
67+
68+
@skip @team:DataDog/fleet-automation
69+
Scenario: Get a deployment by ID returns "OK" response
70+
Given operation "GetFleetDeployment" enabled
71+
And there is a valid "deployment" in the system
72+
And new "GetFleetDeployment" request
73+
And request contains "deployment_id" parameter from "deployment.id"
74+
When the request is sent
75+
Then the response status is 200 OK
76+
77+
@generated @skip @team:DataDog/fleet-automation
78+
Scenario: List all deployments returns "Bad Request" response
79+
Given operation "ListFleetDeployments" enabled
80+
And new "ListFleetDeployments" request
81+
When the request is sent
82+
Then the response status is 400 Bad Request
83+
84+
@generated @skip @team:DataDog/fleet-automation
85+
Scenario: List all deployments returns "OK" response
86+
Given operation "ListFleetDeployments" enabled
87+
And new "ListFleetDeployments" request
88+
When the request is sent
89+
Then the response status is 200 OK

0 commit comments

Comments
 (0)