Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support v2 #8269

Merged
merged 8 commits into from
Jan 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion harbor/datadog_checks/harbor/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
from .common import (
API_VERSION_URL,
CHARTREPO_HEALTH_URL,
HEALTH_URL,
PING_URL,
Expand All @@ -15,11 +16,14 @@
VOLUME_INFO_URL,
)

LEGACY_API_VERSION = 'v1.0'


class HarborAPI(object):
def __init__(self, harbor_url, http):
self.base_url = harbor_url
self.http = http
self.api_version = LEGACY_API_VERSION
self._fetch_and_set_harbor_version()

def chartrepo_health(self):
Expand Down Expand Up @@ -56,6 +60,14 @@ def volume_info(self):
return self._make_get_request(VOLUME_INFO_URL)

def _fetch_and_set_harbor_version(self):
# Only available in v2+
try:
api_version_info = self._make_get_request(API_VERSION_URL)
except Exception:
pass
else:
self.api_version = api_version_info.get('version', LEGACY_API_VERSION)

systeminfo = self._make_get_request(SYSTEM_INFO_URL)
version_str = systeminfo['harbor_version'].split('-')[0].lstrip('v').split('.')[:3]
self.harbor_version = [int(s) for s in version_str]
Expand Down Expand Up @@ -92,4 +104,11 @@ def _make_post_request(self, url, **kwargs):
return resp.json()

def _resolve_url(self, url):
return url.format(base_url=self.base_url)
url = url.format(base_url=self.base_url)

if self.api_version != LEGACY_API_VERSION:
api_path = '{}/api/'.format(self.base_url)
if url.startswith(api_path):
url = url.replace(api_path, '{}{}/'.format(api_path, self.api_version), 1)

return url
1 change: 1 addition & 0 deletions harbor/datadog_checks/harbor/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# All rights reserved
# Licensed under a 3-clause BSD style license (see LICENSE)
SYSTEM_INFO_URL = "{base_url}/api/systeminfo/"
API_VERSION_URL = "{base_url}/api/version"
LOGIN_URL = "{base_url}/c/login/"
LOGIN_PRE_1_7_URL = "{base_url}/login/"
HEALTH_URL = "{base_url}/api/health/"
Expand Down
6 changes: 3 additions & 3 deletions harbor/datadog_checks/harbor/harbor.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def _check_health(self, api, base_tags):
try:
chartrepo_health = api.chartrepo_health()[HEALTHY]
except HTTPError as e:
if e.response.status_code == 403:
if e.response.status_code in (401, 403):
self.log.info(
"Provided user in harbor integration config is not an admin user. Ignoring chartrepo health"
)
Expand All @@ -52,7 +52,7 @@ def _check_registries_health(self, api, base_tags):
registries = api.registries()
self.log.debug("Found %d registries", len(registries))
except HTTPError as e:
if e.response.status_code == 403:
if e.response.status_code in (401, 403):
# Forbidden, user is not admin
self.log.info(
"Provided user in harbor integration config is not an admin user. Ignoring registries health checks"
Expand Down Expand Up @@ -84,7 +84,7 @@ def _submit_disk_metrics(self, api, base_tags):
try:
volume_info = api.volume_info()
except HTTPError as e:
if e.response.status_code == 403:
if e.response.status_code in (401, 403):
# Forbidden, user is not admin
self.log.warning(
"Provided user in harbor integration config is not an admin user. Ignoring volume metrics"
Expand Down
38 changes: 38 additions & 0 deletions harbor/tests/compose/harbor-2.0.5/config/chartserver/env
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
## Settings should be set
PORT=9999

# Only support redis now. If redis is setup, then enable cache
CACHE=redis
CACHE_REDIS_ADDR=redis:6379
CACHE_REDIS_PASSWORD=
CACHE_REDIS_DB=3

# Credential for internal communication
BASIC_AUTH_USER=chart_controller
BASIC_AUTH_PASS=i2DsDOygHVG2pgO3

# Multiple tenants
# Must be set with 1 to support project namespace
DEPTH=1

# Backend storage driver: e.g. "local", "amazon", "google" etc.
STORAGE=local

# Storage driver settings
STORAGE_LOCAL_ROOTDIR=/chart_storage

## Settings with default values. Just put here for future changes
DEBUG=false
LOG_JSON=true
DISABLE_METRICS=false
DISABLE_API=false
DISABLE_STATEFILES=false
ALLOW_OVERWRITE=true
CHART_URL=
AUTH_ANONYMOUS_GET=false
CONTEXT_PATH=
INDEX_LIMIT=0
MAX_STORAGE_OBJECTS=0
MAX_UPLOAD_SIZE=20971520
CHART_POST_FORM_FIELD_NAME=chart
PROV_POST_FORM_FIELD_NAME=prov
6 changes: 6 additions & 0 deletions harbor/tests/compose/harbor-2.0.5/config/core/app.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
appname = Harbor
runmode = dev
enablegzip = true

[dev]
httpport = 8080
55 changes: 55 additions & 0 deletions harbor/tests/compose/harbor-2.0.5/config/core/env
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
CONFIG_PATH=/etc/core/app.conf
UAA_CA_ROOT=/etc/core/certificates/uaa_ca.pem
_REDIS_URL=redis:6379,100,,0,30
SYNC_QUOTA=true
CHART_CACHE_DRIVER=redis
_REDIS_URL_REG=redis://redis:6379/1

PORT=8080
LOG_LEVEL=info
EXT_ENDPOINT=https://localhost
DATABASE_TYPE=postgresql
POSTGRESQL_HOST=postgresql
POSTGRESQL_PORT=5432
POSTGRESQL_USERNAME=postgres
POSTGRESQL_PASSWORD=root123
POSTGRESQL_DATABASE=registry
POSTGRESQL_SSLMODE=disable
POSTGRESQL_MAX_IDLE_CONNS=50
POSTGRESQL_MAX_OPEN_CONNS=1000
REGISTRY_URL=http://registry:5000
TOKEN_SERVICE_URL=http://core:8080/service/token
HARBOR_ADMIN_PASSWORD=Harbor12345
MAX_JOB_WORKERS=10
CORE_SECRET=i2DsDOygHVG2pgO3
JOBSERVICE_SECRET=OAyMVs6vzmKfYe9H
WITH_NOTARY=False
WITH_CLAIR=False
WITH_TRIVY=False
CLAIR_DB_PASSWORD=
CLAIR_DB_HOST=
CLAIR_DB_PORT=
CLAIR_DB_USERNAME=
CLAIR_DB=
CLAIR_DB_SSLMODE=
CORE_URL=http://core:8080
CORE_LOCAL_URL=http://127.0.0.1:8080
JOBSERVICE_URL=http://jobservice:8080
CLAIR_URL=http://clair:6060
CLAIR_ADAPTER_URL=http://clair-adapter:8080
TRIVY_ADAPTER_URL=http://trivy-adapter:8080
NOTARY_URL=http://notary-server:4443
REGISTRY_STORAGE_PROVIDER_NAME=filesystem
READ_ONLY=false
RELOAD_KEY=
CHART_REPOSITORY_URL=http://chartmuseum:9999
REGISTRY_CONTROLLER_URL=http://registryctl:8080
WITH_CHARTMUSEUM=True
REGISTRY_CREDENTIAL_USERNAME=harbor_registry_user
REGISTRY_CREDENTIAL_PASSWORD=jjLARmMfS3KeidxdfsVwyvwIo8d5N92A
CSRF_KEY=IYqWGHvLCLbe41QbowKldiy0B17TCX2R

HTTP_PROXY=
HTTPS_PROXY=
NO_PROXY=portal,registryctl,core,registry,trivy-adapter,log,db,localhost,chartmuseum,notary-server,clair,redis,notary-signer,postgresql,nginx,.internal,jobservice,127.0.0.1,.local,clair-adapter

1 change: 1 addition & 0 deletions harbor/tests/compose/harbor-2.0.5/config/db/env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
POSTGRES_PASSWORD=root123
35 changes: 35 additions & 0 deletions harbor/tests/compose/harbor-2.0.5/config/jobservice/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
---
#Protocol used to serve
protocol: "http"

#Server listening port
port: 8080

#Worker pool
worker_pool:
#Worker concurrency
workers: 10
backend: "redis"
#Additional config if use 'redis' backend
redis_pool:
#redis://[arbitrary_username:password@]ipaddress:port/database_index
redis_url: redis://redis:6379/2
namespace: "harbor_job_service_namespace"
idle_timeout_second: 3600
#Loggers for the running job
job_loggers:
- name: "STD_OUTPUT" # logger backend name, only support "FILE" and "STD_OUTPUT"
level: "INFO" # INFO/DEBUG/WARNING/ERROR/FATAL
- name: "FILE"
level: "INFO"
settings: # Customized settings of logger
base_dir: "/var/log/jobs"
sweeper:
duration: 1 #days
settings: # Customized settings of sweeper
work_dir: "/var/log/jobs"

#Loggers for the job service
loggers:
- name: "STD_OUTPUT" # Same with above
level: "INFO"
13 changes: 13 additions & 0 deletions harbor/tests/compose/harbor-2.0.5/config/jobservice/env
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
CORE_SECRET=i2DsDOygHVG2pgO3
REGISTRY_URL=http://registry:5000
JOBSERVICE_SECRET=OAyMVs6vzmKfYe9H
CORE_URL=http://core:8080
REGISTRY_CONTROLLER_URL=http://registryctl:8080
JOBSERVICE_WEBHOOK_JOB_MAX_RETRY=10


HTTP_PROXY=
HTTPS_PROXY=
NO_PROXY=portal,registryctl,core,registry,trivy-adapter,log,db,localhost,chartmuseum,notary-server,clair,redis,notary-signer,postgresql,nginx,.internal,jobservice,127.0.0.1,.local,clair-adapter
REGISTRY_CREDENTIAL_USERNAME=harbor_registry_user
REGISTRY_CREDENTIAL_PASSWORD=jjLARmMfS3KeidxdfsVwyvwIo8d5N92A
Loading