### Simple Flask 'Hello World' Application Source: https://docs.codenow.com/custom/python-pip-flask-stack A basic Flask application that defines a single route '/' which returns 'Hello World'. This serves as a minimal example for testing the Dockerfile setup. ```python from flask import Flask app = Flask(__name__) @app.route('/') def hello(): return 'Hello World' if __name__ == '__main__': app.run() ``` -------------------------------- ### POST /ci/webhook - Start Event Source: https://docs.codenow.com/custom/external-ci-example Send a 'codenow.ci.start.event' to indicate the start of an external CI pipeline execution. This event is mandatory for each pipeline run. ```APIDOC ## POST /ci/webhook ### Description Sends a start event to CodeNOW to signify the beginning of an external CI pipeline execution. This event initializes a new build in the component details. ### Method POST ### Endpoint `https://api.cloud.codenow.com/ci/webhook` ### Parameters #### Headers - **Accept** (string) - Required - `application/vnd.codenow.v1+json` - **Content-Type** (string) - Required - `application/vnd.codenow.v1+json` - **X-Codenow-Api-Key** (string) - Required - Your CI Key #### Request Body - **type** (string) - Required - `codenow.ci.start.event` - **version** (string) - Required - `application/vnd.codenow.v1+json` - **pipelineId** (string) - Required - Unique identifier for the pipeline run. - **componentId** (string) - Required - Technical Name (ID) of the CodeNOW component. - **buildVersion** (string) - Required - The version of the build. - **createdAt** (string) - Required - Timestamp of event creation (ISO 8601 format). - **actor** (object) - Required - Information about the user triggering the pipeline. - **username** (string) - Required - Username of the actor. - **fullname** (string) - Optional - Full name of the actor. - **pipelineName** (string) - Optional - Name of the pipeline. - **dashboardUrl** (string) - Optional - URL to the pipeline dashboard. ### Request Example ```json { "type": "codenow.ci.start.event", "version": "application/vnd.codenow.v1+json", "pipelineId": "my-pipeline-id", "componentId": "my-component-id", "buildVersion": "0.0.1", "createdAt": "2024-01-01T00:00:00.000Z", "actor": { "username": "johnsmith", "fullname": "John Smith" }, "pipelineName": "My Pipeline", "dashboardUrl": "https://my-dashboard.com" } ``` ### Response #### Success Response (200) (No specific response body detailed in the example, typically indicates successful receipt of the event.) #### Response Example (N/A - Success indicated by lack of error) ``` -------------------------------- ### Build Node.js Application Docker Image Source: https://docs.codenow.com/glossary This Dockerfile defines the steps to build a Docker image for a Node.js application. It starts from a Node.js base image, copies the application code, installs dependencies, sets the working directory, exposes the application port, and defines the command to run the application. ```dockerfile FROM node:14-alpine COPY . /app RUN rm -rf /app/node_modules/.bin WORKDIR /app EXPOSE 3000 RUN npm rebuild CMD [ "npm", "run", "serve" ] ``` -------------------------------- ### PostgreSQL Connection String Example Source: https://docs.codenow.com/advanced-features/component-service-connection An example of a PostgreSQL connection string configuration using environment variables. This format is common in applications needing to connect to a PostgreSQL database and assumes environment variables are set by the CodeNOW platform during deployment. ```text "Host=${POSTGRESQL_HOST};Port=${POSTGRESQL_PORT};Database=${POSTGRESQL_DATABASE_NAME};User Id=${POSTGRESQL_USERNAME};Password=${POSTGRESQL_PASSWORD}" ``` -------------------------------- ### Send CI Start Event via cURL Source: https://docs.codenow.com/custom/external-ci-example This cURL command sends a 'codenow.ci.start.event' to initiate a CI pipeline run in CodeNOW. It requires your CI Key, component ID, build version, and creation timestamp. The event signals the beginning of the pipeline execution and will create a new build entry in the component's detail. ```bash curl -L -X POST 'https://api.cloud.codenow.com/ci/webhook' \ --header 'Accept: application/vnd.codenow.v1+json' \ --header 'Content-Type: application/vnd.codenow.v1+json' \ --header 'X-Codenow-Api-Key: {YOUR_CI_KEY}' \ --data-raw '{ \ "type": "codenow.ci.start.event", \ "version": "application/vnd.codenow.v1+json", \ "pipelineId": "my-pipeline-id", \ "componentId": "my-component-id", \ "buildVersion": "0.0.1", \ "createdAt": "2024-01-01T00:00:00.000Z", \ "actor": { \ "username": "johnsmith", \ "fullname": "John Smith" \ }, \ "pipelineName": "My Pipeline", \ "dashboardUrl": "https://my-dashboard.com" \ }' ``` -------------------------------- ### Example API Request with Versioning using cURL Source: https://docs.codenow.com/api/overview/api-versions This cURL command shows a GET request to the '/environments' endpoint, specifying API version 1 and including an API key in the headers. ```bash curl -X GET \ -H "Accept: application/vnd.codenow.v1+json" \ -H "X-Codenow-Api-Key: Bearer YOUR_API_KEY" \ https://api.codenow.com/environments ``` -------------------------------- ### Dockerfile for Python/Flask Application Source: https://docs.codenow.com/custom/python-pip-flask-stack This Dockerfile sets up a Python 3.9 environment with Flask, installs dependencies from requirements.txt, and exposes port 80 for the application. It assumes the application code is in the 'src' directory and the entry point is 'app.py'. ```dockerfile # Source image FROM python:3.9.12-alpine3.15 # Create a virtual environment for all the Python dependencies RUN python3 -m venv /opt/venv # Make sure we use the virtualenv ENV PATH="/opt/venv/bin:$PATH" # Change workdir to app directory WORKDIR /app # Copy content of src directory into /app dir COPY src/ . # Install Python dependencies RUN pip3 install -r requirements.txt # Expose application port EXPOSE 80 # start the application CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0", "--port=80"] ``` -------------------------------- ### Configure Kafka and Redis (YAML) Source: https://docs.codenow.com/java-micronaut-examples/java-micronaut-rest-server-with-redis-and-kafka Appends configuration for Kafka and Redis to the application.yaml file. This includes Redis URI and Kafka bootstrap servers and topic details, essential for local development setup. ```yaml redis: uri: redis://localhost:6379 kafka: bootstrap: servers: localhost:29092 topic: name: client-logging key: client-authorization-service ``` -------------------------------- ### GET /clients Source: https://docs.codenow.com/java-micronaut-examples/java-micronaut-rest-server-with-cockroach-db Retrieves a list of all clients from the database. ```APIDOC ## GET /clients ### Description Return all clients from the database. ### Method GET ### Endpoint /clients #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **data** (array) - A list of client objects. - **id** (string) - The unique identifier for the client. - **username** (string) - The username of the client. - **firstname** (string) - The first name of the client. - **surname** (string) - The surname of the client. - **birthdate** (string) - The birthdate of the client. #### Response Example ```json [ { "id": "123e4567-e89b-12d3-a456-426614174000", "username": "johndoe", "firstname": "John", "surname": "Doe", "birthdate": "1990-01-01T00:00:00Z" } ] ``` #### Error Response (400) - **errorId** (string) - Unique ID for the error. - **traceId** (string) - Trace ID for the error. - **errorDetail** (string) - Detailed error message. - **errorParams** (array) - An array of error parameters. - **requestMapping** (array) - An array of request mapping strings. #### Error Response Example (400) ```json { "errorId": "abcde-12345", "traceId": "fghij-67890", "errorDetail": "Invalid input provided.", "errorParams": [ { "key": "fieldName", "value": "fieldValue" } ], "requestMapping": [ "mapping1", "mapping2" ] } ``` #### Error Response (500) - **errorId** (string) - Unique ID for the error. - **traceId** (string) - Trace ID for the error. - **errorDetail** (string) - Detailed error message. #### Error Response Example (500) ```json { "errorId": "klmno-54321", "traceId": "pqrst-09876", "errorDetail": "An internal server error occurred." } ``` ``` -------------------------------- ### Configure Zipkin and Sleuth for CodeNOW Jaeger Collector (YAML) Source: https://docs.codenow.com/java-spring-boot-complex-examples/java-spring-boot-tracing Enables Zipkin and configures the base URL for the CodeNOW Jaeger collector. This setup is for integrating with a deployed Jaeger instance within the CodeNOW environment. ```yaml spring: zipkin: enabled: true baseUrl: http://tracing-jaeger-collector.tracing-system:9411 sleuth: propagation: type: B3 tag: enabled: true ``` -------------------------------- ### Set Accept Header for API Version 1 Source: https://docs.codenow.com/api/overview/api-versions This example demonstrates how to set the 'Accept' header to request version 1 of an API operation using the 'application/vnd.codenow.vX+json' format. ```http Accept: application/vnd.codenow.v1+json ``` -------------------------------- ### Flask Application Dependencies Source: https://docs.codenow.com/custom/python-pip-flask-stack This file lists the Python dependencies required for the Flask application, specifying the version of Flask to be installed. It is used by pip to install packages during the Docker image build process. ```python-requirements flask==2.1.1 ``` -------------------------------- ### SSH Configuration Example Source: https://docs.codenow.com/users-administration/ssh-settings This configuration snippet shows how to set up SSH to connect to a Git server. It specifies the host, preferred authentication method, port, and the identity file for the SSH key. Ensure you replace the placeholder with your actual generated SSH key. ```bash Host gitlab.factory.innobank.codenow.com Preferredauthentications publickey Port 22 IdentityFile ~/.ssh/id_ed25519 ``` -------------------------------- ### Add Spring Boot Security and Keycloak Dependencies (pom.xml) Source: https://docs.codenow.com/java-spring-boot-complex-examples/secured-spring-boot-rest-api-with-keycloak Add the necessary Spring Boot Starter Security and Keycloak dependencies to your project's pom.xml. This includes the main starter, the Keycloak Spring Boot starter, and the adapter, along with the Keycloak adapter BOM for dependency management. ```xml org.springframework.boot spring-boot-starter-security org.keycloak keycloak-spring-boot-starter org.keycloak keycloak-spring-security-adapter 10.0.0 org.keycloak.bom keycloak-adapter-bom 10.0.0 pom import ``` -------------------------------- ### GET /users Source: https://docs.codenow.com/custom/nodejs-npm-express-api-postgres Retrieves a list of all users. ```APIDOC ## GET /users ### Description Retrieves a list of all users. ### Method GET ### Endpoint /users ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **users** (array) - A list of user objects. - **id** (integer) - The unique identifier for the user. - **username** (string) - The username of the user. #### Response Example { "users": [ { "id": 1, "username": "john_doe" } ] } ``` -------------------------------- ### Configure Kafka Application Properties (YAML) Source: https://docs.codenow.com/java-spring-boot-complex-examples/java-spring-boot-kafka-producer-consumer Sets up Kafka connection details and topic configurations in the application.yaml file. This includes bootstrap servers, topic names, and consumer group IDs for different services. ```yaml kafka: order: bootstrap-servers: ${KAFKA_RESERVATION_BOOTSTRAP_SERVERS:localhost:9092} topic: create-order: create-order consumer: group-id: notification: notification service: service ``` -------------------------------- ### GET /messages Source: https://docs.codenow.com/custom/nodejs-npm-express-api-postgres Retrieves a list of all messages from the API. ```APIDOC ## GET /messages ### Description Retrieves a list of all messages. ### Method GET ### Endpoint /messages ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **messages** (array) - A list of message objects. - **id** (integer) - The unique identifier for the message. - **text** (string) - The content of the message. - **created_at** (string) - The timestamp when the message was created. #### Response Example { "messages": [ { "id": 1, "text": "Hello, World!", "created_at": "2023-10-27T10:00:00Z" } ] } ``` -------------------------------- ### GET /clients/{username} Source: https://docs.codenow.com/java-micronaut-examples/java-micronaut-rest-server-with-cockroach-db Retrieves a specific client by their username. ```APIDOC ## GET /clients/{username} ### Description Return client by username. ### Method GET ### Endpoint /clients/{username} #### Path Parameters - **username** (string) - Required - The username of the client to retrieve. #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **id** (string) - The unique identifier for the client. - **username** (string) - The username of the client. - **firstname** (string) - The first name of the client. - **surname** (string) - The surname of the client. - **birthdate** (string) - The birthdate of the client. #### Response Example ```json { "id": "123e4567-e89b-12d3-a456-426614174000", "username": "johndoe", "firstname": "John", "surname": "Doe", "birthdate": "1990-01-01T00:00:00Z" } ``` #### Error Response (400) - **errorId** (string) - Unique ID for the error. - **traceId** (string) - Trace ID for the error. - **errorDetail** (string) - Detailed error message. - **errorParams** (array) - An array of error parameters. - **requestMapping** (array) - An array of request mapping strings. #### Error Response Example (400) ```json { "errorId": "abcde-12345", "traceId": "fghij-67890", "errorDetail": "Invalid input provided.", "errorParams": [ { "key": "fieldName", "value": "fieldValue" } ], "requestMapping": [ "mapping1", "mapping2" ] } ``` #### Error Response (500) - **errorId** (string) - Unique ID for the error. - **traceId** (string) - Trace ID for the error. - **errorDetail** (string) - Detailed error message. #### Error Response Example (500) ```json { "errorId": "klmno-54321", "traceId": "pqrst-09876", "errorDetail": "An internal server error occurred." } ``` ``` -------------------------------- ### Manual Span Creation and Management (Java) Source: https://docs.codenow.com/java-spring-boot-complex-examples/java-spring-boot-tracing This code snippet demonstrates how to manually create and manage a Sleuth span using the TracingHelper. It highlights the importance of starting the span using `spanInScope` and ensuring it is ended in a `finally` block to handle potential exceptions. ```java Span span = tracingHelper.createClientSpan("Legacy App 1", "service", this.getClass().getName()) try(Tracer.SpanInScope ws = tracingHelper.spanInScope(span)){ // Enter your code here } finally { span.end(); } ``` -------------------------------- ### Configure Redis Connection in Java Source: https://docs.codenow.com/java-spring-boot-complex-examples/java-spring-boot-rest-server-with-redis-and-kafka Sets up a Spring configuration class for Redis, establishing a connection factory using Lettuce client and a provided Redis URI. Requires Spring Data Redis and Lettuce libraries. ```java import io.lettuce.core.RedisClient; import io.lettuce.core.RedisURI; import io.lettuce.core.api.StatefulRedisConnection; import io.lettuce.core.api.sync.RedisCommands; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.data.redis.repository.configuration.EnableRedisRepositories; @Configuration @EnableRedisRepositories public class RedisConfig { @Value("${spring.redis.url}") private String uri; @Bean public RedisCommands connectionFactory() { RedisURI redisURI = RedisURI.create(uri); RedisClient redisClient = RedisClient.create(redisURI); StatefulRedisConnection redisConnection = redisClient.connect(); return redisConnection.sync(); } } ``` -------------------------------- ### GET /users/{id} Source: https://docs.codenow.com/custom/nodejs-npm-express-api-postgres Retrieves a specific user by their ID. ```APIDOC ## GET /users/{id} ### Description Retrieves a specific user by their ID. ### Method GET ### Endpoint /users/{id} ### Parameters #### Path Parameters - **id** (integer) - Required - The unique identifier of the user to retrieve. #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **id** (integer) - The unique identifier for the user. - **username** (string) - The username of the user. #### Response Example { "id": 1, "username": "john_doe" } ``` -------------------------------- ### Create `ClientDataController` Source: https://docs.codenow.com/java-spring-boot-complex-examples/java-spring-boot-rest-server-with-postgresql This Java controller exposes REST endpoints for accessing client data. It uses `ClientRepository` to fetch all clients or a specific client by username. It's annotated with `@RestController` and `@RequestMapping` for web request handling. ```java package org.example.service.controller; import org.example.service.repository.ClientRepository; import org.example.service.repository.entity.Client; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RestController; import reactor.core.publisher.Flux; import javax.validation.constraints.NotNull; import java.util.List; @RestController @RequestMapping("/db") public class ClientDataController { private final ClientRepository clientRepository; @Autowired public ClientDataController(ClientRepository clientRepository) { this.clientRepository = clientRepository; } @GetMapping("/clients") public List listClients() { return clientRepository.findAll(); } @GetMapping("/clients/{username}") public Flux getClient(@PathVariable @NotNull String username) { return Flux.just(clientRepository.getClientByUsername(username)); } } ``` -------------------------------- ### GET /messages/{id} Source: https://docs.codenow.com/custom/nodejs-npm-express-api-postgres Retrieves a specific message by its ID. ```APIDOC ## GET /messages/{id} ### Description Retrieves a specific message by its ID. ### Method GET ### Endpoint /messages/{id} ### Parameters #### Path Parameters - **id** (integer) - Required - The unique identifier of the message to retrieve. #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **id** (integer) - The unique identifier for the message. - **text** (string) - The content of the message. - **created_at** (string) - The timestamp when the message was created. #### Response Example { "id": 1, "text": "Hello, World!", "created_at": "2023-10-27T10:00:00Z" } ``` -------------------------------- ### Add Spring Boot and PostgreSQL Maven Dependencies Source: https://docs.codenow.com/java-spring-boot-complex-examples/java-spring-boot-rest-server-with-cockroachdb This snippet shows the essential Maven dependencies required for a Spring Boot application with JPA and PostgreSQL database integration. It includes spring-boot-starter, spring-boot-starter-data-jpa, hibernate-core, and the PostgreSQL JDBC driver. ```xml org.springframework.boot spring-boot-starter 2.3.3.RELEASE org.springframework.boot spring-boot-starter-data-jpa 2.3.3.RELEASE org.hibernate hibernate-core 5.4.21.Final org.postgresql postgresql 42.2.11 ``` -------------------------------- ### POST /ci/webhook Source: https://docs.codenow.com/custom/external-ci-example Send the end event to finish the pipeline execution and report the result. ```APIDOC ## POST /ci/webhook ### Description Send the `codenow.ci.end.event` to report the result of the whole pipeline execution. This signifies the completion of the pipeline. ### Method POST ### Endpoint `/ci/webhook` ### Parameters #### Headers - **Accept** (string) - Required - `application/vnd.codenow.v1+json` - **Content-Type** (string) - Required - `application/vnd.codenow.v1+json` - **X-Codenow-Api-Key** (string) - Required - Your Codenow CI API Key #### Request Body - **type** (string) - Required - Must be `codenow.ci.end.event` - **version** (string) - Required - `application/vnd.codenow.v1+json` - **pipelineId** (string) - Required - The unique identifier for the pipeline run. - **createdAt** (string) - Required - The timestamp when the event occurred (ISO 8601 format). - **result** (string) - Required - The outcome of the pipeline. Accepted values: `SUCCESSFUL`, `FAILED`, `CANCELED` ### Request Example ```json { "type": "codenow.ci.end.event", "version": "application/vnd.codenow.v1+json", "pipelineId": "my-pipeline-id", "createdAt": "2024-01-01T00:00:00.000Z", "result": "SUCCESSFUL" } ``` ### Response #### Success Response (200) Upon successful receipt of the end event, the pipeline run is considered finished. The result will be visible in the build history. No specific response body is detailed in the documentation, but a successful status code is expected. ```