Skip to content

Commit

Permalink
Merge pull request #718 from MetaCell/feature/CH-47
Browse files Browse the repository at this point in the history
Add tag / build reference api
  • Loading branch information
filippomc authored Feb 1, 2024
2 parents fe96676 + 3343f8b commit 3e9b12d
Show file tree
Hide file tree
Showing 16 changed files with 362 additions and 77 deletions.
175 changes: 104 additions & 71 deletions applications/common/api/openapi.yaml
Original file line number Diff line number Diff line change
@@ -1,78 +1,111 @@
openapi: 3.0.0
info:
description: Cloud Harness Platform - Reference CH service API
license:
name: UNLICENSED
title: CH common service API
version: 0.1.0
title: CH common service API
version: 0.1.0
description: Cloud Harness Platform - Reference CH service API
license:
name: UNLICENSED
servers:
- description: SwaggerHub API Auto Mocking
url: /api
tags:
- description: Sentry
name: Sentry
-
url: /api
description: SwaggerHub API Auto Mocking
paths:
/sentry/getdsn/{appname}:
parameters:
- in: path
name: appname
schema:
type: string
required: true
get:
tags:
- Sentry
description: Gets the Sentry DSN for a given application
operationId: getdsn
responses:
'200':
description: Sentry DSN for the given application
content:
application/json:
schema:
type: object
'400':
description: Sentry not configured for the given application
content:
application/json:
schema:
type: object
text/html:
schema:
type: string
'404':
description: Sentry not configured for the given application
content:
application/problem+json:
schema:
type: object
text/html:
schema:
type: string
summary: Gets the Sentry DSN for a given application
x-openapi-router-controller: common.controllers.sentry_controller
/accounts/config:
get:
tags:
- Accounts
description: Gets the config for logging in into accounts
operationId: get_config
responses:
'200':
description: Config for accounts log in
content:
application/json:
schema:
type: object
properties:
url:
'/sentry/getdsn/{appname}':
get:
tags:
- Sentry
responses:
'200':
content:
application/json:
schema:
type: object
description: Sentry DSN for the given application
'400':
content:
application/json:
schema:
type: object
text/html:
schema:
type: string
description: Sentry not configured for the given application
'404':
content:
application/problem+json:
schema:
type: object
text/html:
schema:
type: string
description: Sentry not configured for the given application
operationId: getdsn
summary: Gets the Sentry DSN for a given application
description: Gets the Sentry DSN for a given application
x-openapi-router-controller: common.controllers.sentry_controller
parameters:
-
name: appname
schema:
type: string
description: The auth URL.
realm:
in: path
required: true
/accounts/config:
get:
tags:
- Accounts
responses:
'200':
content:
application/json:
schema:
type: object
properties:
url:
description: The auth URL.
type: string
realm:
description: The realm.
type: string
clientId:
description: The clientID.
type: string
description: Config for accounts log in
operationId: get_config
summary: Gets the config for logging in into accounts
description: Gets the config for logging in into accounts
x-openapi-router-controller: common.controllers.accounts_controller
/version:
summary: Get the version for this deployment
get:
tags:
- config
responses:
'200':
content:
application/json:
schema:
$ref: '#/components/schemas/AppVersion'
examples:
version:
value: "{\r\n \"build\": \"63498f19146bae1a6ae7e354\"\r\n \"tag\": \"v1.2.0\"\r\n}"
description: Deployment version GET
operationId: getVersion
components:
schemas:
AppVersion:
title: Root Type for AppVersion
description: ''
type: object
properties:
build:
type: string
description: The realm.
clientId:
tag:
type: string
description: The clientID.
summary: Gets the config for logging in into accounts
x-openapi-router-controller: common.controllers.accounts_controller
example:
build: 63498f19146bae1a6ae7e354
tag: v1.2.0
tags:
-
name: Sentry
description: Sentry
25 changes: 25 additions & 0 deletions applications/common/server/common/controllers/config_controller.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

import connexion
import six
from typing import Dict
from typing import Tuple
from typing import Union

from common.models.app_version import AppVersion # noqa: E501
from common import util

from cloudharness.utils.config import CloudharnessConfig
from cloudharness_model.models import HarnessMainConfig

def get_version(): # noqa: E501
"""get_version
# noqa: E501
:rtype: Union[AppVersion, Tuple[AppVersion, int], Tuple[AppVersion, int, Dict[str, str]]
"""

config: HarnessMainConfig = HarnessMainConfig.from_dict(CloudharnessConfig.get_configuration())

return AppVersion(tag=config.tag, build=config.build_hash)
1 change: 1 addition & 0 deletions applications/common/server/common/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@
# flake8: noqa
from __future__ import absolute_import
# import models into model package
from common.models.app_version import AppVersion
from common.models.get_config200_response import GetConfig200Response
90 changes: 90 additions & 0 deletions applications/common/server/common/models/app_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
# coding: utf-8

from __future__ import absolute_import
from datetime import date, datetime # noqa: F401

from typing import List, Dict # noqa: F401

from common.models.base_model_ import Model
from common import util


class AppVersion(Model):
"""NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
Do not edit the class manually.
"""

def __init__(self, build=None, tag=None): # noqa: E501
"""AppVersion - a model defined in OpenAPI
:param build: The build of this AppVersion. # noqa: E501
:type build: str
:param tag: The tag of this AppVersion. # noqa: E501
:type tag: str
"""
self.openapi_types = {
'build': str,
'tag': str
}

self.attribute_map = {
'build': 'build',
'tag': 'tag'
}

self._build = build
self._tag = tag

@classmethod
def from_dict(cls, dikt) -> 'AppVersion':
"""Returns the dict as a model
:param dikt: A dict.
:type: dict
:return: The AppVersion of this AppVersion. # noqa: E501
:rtype: AppVersion
"""
return util.deserialize_model(dikt, cls)

@property
def build(self):
"""Gets the build of this AppVersion.
:return: The build of this AppVersion.
:rtype: str
"""
return self._build

@build.setter
def build(self, build):
"""Sets the build of this AppVersion.
:param build: The build of this AppVersion.
:type build: str
"""

self._build = build

@property
def tag(self):
"""Gets the tag of this AppVersion.
:return: The tag of this AppVersion.
:rtype: str
"""
return self._tag

@tag.setter
def tag(self, tag):
"""Sets the tag of this AppVersion.
:param tag: The tag of this AppVersion.
:type tag: str
"""

self._tag = tag
30 changes: 30 additions & 0 deletions applications/common/server/common/openapi/openapi.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,38 @@ paths:
tags:
- Sentry
x-openapi-router-controller: common.controllers.sentry_controller
/version:
get:
operationId: get_version
responses:
"200":
content:
application/json:
examples:
version:
value: "{\r\n \"build\": \"63498f19146bae1a6ae7e354\"\r\n \"tag\"\
: \"v1.2.0\"\r\n}"
schema:
$ref: '#/components/schemas/AppVersion'
description: Deployment version GET
tags:
- config
x-openapi-router-controller: common.controllers.config_controller
summary: Get the version for this deployment
components:
schemas:
AppVersion:
description: ""
example:
build: 63498f19146bae1a6ae7e354
tag: v1.2.0
properties:
build:
type: string
tag:
type: string
title: Root Type for AppVersion
type: object
get_config_200_response:
example:
clientId: clientId
Expand Down
1 change: 1 addition & 0 deletions applications/jupyterhub/zero-to-jupyterhub-k8s
Submodule zero-to-jupyterhub-k8s added at c92c12
3 changes: 3 additions & 0 deletions applications/samples/deploy/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ harness:
service:
port: 8080
auto: true
use_services:
- name: common
deployment:
volume:
name: my-shared-volume
Expand Down Expand Up @@ -47,6 +49,7 @@ harness:
build:
- cloudharness-flask
- cloudharness-frontend-build

resources:
- name: my-config
src: "myConfig.json"
Expand Down
3 changes: 2 additions & 1 deletion applications/samples/frontend/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@ import React from 'react';
import './styles/style.less';

import RestTest from './components/RestTest';

import Version from './components/Version';

const Main = () => (
<>
<img src="/assets/icon.png" width="800" />
<h1>Sample React application is working!</h1>
<Version />
<RestTest />
<p>See api documentation <a href="/api/ui/">here</a></p>
</>
Expand Down
19 changes: 19 additions & 0 deletions applications/samples/frontend/src/components/Version.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import React, { useState, useEffect } from 'react';



const Version = () => {
const [result, setResult] = useState(null);
useEffect(() => {
fetch("/proxy/common/api/version", {
headers: {
'Accept': 'application/json'
}
}).then(r => r.json().then(j => setResult(j)), () => setResult({ data: "API error" }));
}, []);


return result ? <p>Tag: { result?.tag } - Build: {result?.build} </p> : <p>Backend did not answer</p>
}

export default Version;
Loading

0 comments on commit 3e9b12d

Please sign in to comment.