Skip to content

Commit

Permalink
add e2e lab and update config
Browse files Browse the repository at this point in the history
  • Loading branch information
sarah-witt committed Oct 21, 2024
1 parent 6a88501 commit 75396e8
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 59 deletions.
14 changes: 14 additions & 0 deletions octopus_deploy/assets/configuration/spec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ files:
- template: instances
options:
- name: octopus_endpoint
display_priority: 8
description: |
Octopus API endpoint.
See https://octopus.com/docs/octopus-rest-api/getting-started#authentication for more details.
Expand All @@ -17,6 +18,7 @@ files:
type: string
required: true
- name: space
display_priority: 7
description: |
Space to monitor
value:
Expand All @@ -25,6 +27,7 @@ files:
enabled: true
required: true
- name: project_groups
display_priority: 5
description: |
filter your integration by project groups and projects.
value:
Expand All @@ -49,4 +52,15 @@ files:
example: {}
- template: instances/default
- template: instances/http
overrides:
headers.display_priority: 6
headers.enabled: true
headers.description: |
Headers to use for every request. An Authorization header including the Octopus Deploy API key token is required
for authentication for the REST API.
You can alternatively use the `auth_token` option.
headers.value.example:
X-Octopus-ApiKey: "<OCTOPUS_API_KEY>"
auth_token.display_priority: 4

97 changes: 47 additions & 50 deletions octopus_deploy/datadog_checks/octopus_deploy/data/conf.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,58 @@ instances:
#
space: Default

## @param headers - mapping - optional
## Headers to use for every request. An Authorization header including the Octopus Deploy API key token is required
## for authentication for the REST API.
## You can alternatively use the `auth_token` option.
#
headers:
X-Octopus-ApiKey: <OCTOPUS_API_KEY>

## @param project_groups - mapping - optional
## filter your integration by project groups and projects.
#
# project_groups: {}

## @param auth_token - mapping - optional
## This allows for the use of authentication information from dynamic sources.
## Both a reader and writer must be configured.
##
## The available readers are:
##
## - type: file
## path (required): The absolute path for the file to read from.
## pattern: A regular expression pattern with a single capture group used to find the
## token rather than using the entire file, for example: Your secret is (.+)
## - type: oauth
## url (required): The token endpoint.
## client_id (required): The client identifier.
## client_secret (required): The client secret.
## basic_auth: Whether the provider expects credentials to be transmitted in
## an HTTP Basic Auth header. The default is: false
## options: Mapping of additional options to pass to the provider, such as the audience
## or the scope. For example:
## options:
## audience: https://example.com
## scope: read:example
##
## The available writers are:
##
## - type: header
## name (required): The name of the field, for example: Authorization
## value: The template value, for example `Bearer <TOKEN>`. The default is: <TOKEN>
## placeholder: The substring in `value` to replace with the token, defaults to: <TOKEN>
#
# auth_token:
# reader:
# type: <READER_TYPE>
# <OPTION_1>: <VALUE_1>
# <OPTION_2>: <VALUE_2>
# writer:
# type: <WRITER_TYPE>
# <OPTION_1>: <VALUE_1>
# <OPTION_2>: <VALUE_2>

## @param tags - list of strings - optional
## A list of tags to attach to every metric and service check emitted by this instance.
##
Expand Down Expand Up @@ -239,45 +286,6 @@ instances:
#
# kerberos_keytab: <KEYTAB_FILE_PATH>

## @param auth_token - mapping - optional
## This allows for the use of authentication information from dynamic sources.
## Both a reader and writer must be configured.
##
## The available readers are:
##
## - type: file
## path (required): The absolute path for the file to read from.
## pattern: A regular expression pattern with a single capture group used to find the
## token rather than using the entire file, for example: Your secret is (.+)
## - type: oauth
## url (required): The token endpoint.
## client_id (required): The client identifier.
## client_secret (required): The client secret.
## basic_auth: Whether the provider expects credentials to be transmitted in
## an HTTP Basic Auth header. The default is: false
## options: Mapping of additional options to pass to the provider, such as the audience
## or the scope. For example:
## options:
## audience: https://example.com
## scope: read:example
##
## The available writers are:
##
## - type: header
## name (required): The name of the field, for example: Authorization
## value: The template value, for example `Bearer <TOKEN>`. The default is: <TOKEN>
## placeholder: The substring in `value` to replace with the token, defaults to: <TOKEN>
#
# auth_token:
# reader:
# type: <READER_TYPE>
# <OPTION_1>: <VALUE_1>
# <OPTION_2>: <VALUE_2>
# writer:
# type: <WRITER_TYPE>
# <OPTION_1>: <VALUE_1>
# <OPTION_2>: <VALUE_2>

## @param aws_region - string - optional
## If your services require AWS Signature Version 4 signing, set the region.
##
Expand Down Expand Up @@ -357,17 +365,6 @@ instances:
# - TLSv1.2
# - TLSv1.3

## @param headers - mapping - optional
## The headers parameter allows you to send specific headers with every request.
## You can use it for explicitly specifying the host header or adding headers for
## authorization purposes.
##
## This overrides any default headers.
#
# headers:
# Host: <ALTERNATIVE_HOSTNAME>
# X-Auth-Token: <AUTH_TOKEN>

## @param extra_headers - mapping - optional
## Additional headers to send with every request.
#
Expand Down
15 changes: 15 additions & 0 deletions octopus_deploy/hatch.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,18 @@

[[envs.default.matrix]]
python = ["3.12"]
setup = ["caddy"]

[[envs.default.matrix]]
python = ["3.12"]
setup = ["lab"]

[envs.default.overrides]
name."caddy".e2e-env = { value = true }
matrix.setup.e2e-env = { value = true, if = ["lab"], env = ["OCTOPUS_LAB_ENDPOINT", "OCTOPUS_API_KEY"] }
matrix.setup.env-vars = [
{ key = "USE_OCTOPUS_LAB", value = "True", if = ["lab"] },
]

[envs.default]
e2e-env = false
21 changes: 12 additions & 9 deletions octopus_deploy/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,22 @@
from datadog_checks.dev.conditions import CheckDockerLogs, CheckEndpoints
from datadog_checks.dev.fs import get_here

from .constants import COMPOSE_FILE, INSTANCE
from .constants import COMPOSE_FILE, INSTANCE, LAB_INSTANCE, USE_OCTOPUS_LAB


@pytest.fixture(scope='session')
def dd_environment():
compose_file = COMPOSE_FILE
endpoint = INSTANCE["octopus_endpoint"]
conditions = [
CheckDockerLogs(identifier='octopus-api', patterns=['server running']),
CheckEndpoints(f'{endpoint}/spaces'),
]
with docker_run(compose_file, conditions=conditions):
yield INSTANCE
if USE_OCTOPUS_LAB:
yield LAB_INSTANCE
else:
compose_file = COMPOSE_FILE
endpoint = INSTANCE["octopus_endpoint"]
conditions = [
CheckDockerLogs(identifier='octopus-api', patterns=['server running']),
CheckEndpoints(f'{endpoint}/spaces'),
]
with docker_run(compose_file, conditions=conditions):
yield INSTANCE


@pytest.fixture
Expand Down
11 changes: 11 additions & 0 deletions octopus_deploy/tests/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,20 @@
from datadog_checks.base.utils.time import ensure_aware_datetime
from datadog_checks.dev.fs import get_here

USE_OCTOPUS_LAB = os.environ.get("USE_OCTOPUS_LAB")
OCTOPUS_LAB_ENDPOINT = os.environ.get('OCTOPUS_LAB_ENDPOINT')
OCTOPUS_API_KEY = os.environ.get('OCTOPUS_API_KEY')
OCTOPUS_SPACE = os.environ.get('OCTOPUS_SPACE', 'Default')

COMPOSE_FILE = os.path.join(get_here(), 'docker', 'docker-compose.yaml')
INSTANCE = {'octopus_endpoint': 'http://localhost:80/api', 'space': 'Default'}

LAB_INSTANCE = {
'octopus_endpoint': OCTOPUS_LAB_ENDPOINT,
'space': OCTOPUS_SPACE,
'headers': {'X-Octopus-ApiKey': OCTOPUS_API_KEY},
}


BASE_TIME = ensure_aware_datetime(datetime.datetime.strptime("2024-09-23 14:45:58.888492", '%Y-%m-%d %H:%M:%S.%f'))
MOCKED_TIMESTAMPS = [BASE_TIME] * 20
Expand Down

0 comments on commit 75396e8

Please sign in to comment.