Skip to content

Commit

Permalink
Added support for public code
Browse files Browse the repository at this point in the history
  • Loading branch information
rubenvdlinde committed Dec 28, 2019
1 parent 76a6fcc commit 2531b6a
Show file tree
Hide file tree
Showing 16 changed files with 371 additions and 26 deletions.
4 changes: 4 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ APP_BUILD=dev
# The description for this api
APP_DESCRIPTION='Naast deze JSON rest API is er ook een [graphql](/graphql) interface beschikbaar.'


APP_LOGO=pc.zaakonline.nl
APP_HOME=pc.zaakonline.nl

# The urls on wich this api is available
TRUSTED_PROXIES=10.0.0.0/8,172.16.0.0/12,192.168.0.0/16
TRUSTED_HOSTS=^(.+\.)?conduction\.nl$|^(.+\.)?vng\.cloud$|^(.+\.)?huwelijksplanner\.online$|^(.+\.)?larping\.eu$|^(.+\.)?common-ground\.dev$|^(.+\.)?trouwplanner\.online$|^(.+\.)?zaakonline\.nl$|localhost
Expand Down
1 change: 1 addition & 0 deletions AUTHORS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# AUTHORS
1 change: 1 addition & 0 deletions ROADMAP.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Roadmap
10 changes: 2 additions & 8 deletions TUTORIAL.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,15 +306,9 @@ More information on using data fixtures can be found at the [symfony website](ht
## Sharing your work
A vital part of te common ground community is sharing your work, and telling other people what you are working. This way people can help you with problems that you run into. And keep tabs on any (security) updates that you make to you code. Sounds like a lot of work right?

Wel it actually isn't, there is a specific common ground platform over at common-ground.dev that reads repositories and updates user. So the only thing we need to do is tell this platform that we have started a new common ground repository. And tell it when we have updates ours. We can do all that by simply adding a webhook to our component.
Wel it actually isn't, there is a specific common ground platform over at common-ground.dev that reads repositories and updates user. So the only thing we need to do is tell this platform that we have started a new common ground repository. How do we do that? Simple we use the name common ground (or commonground) in the discription of our repository. common-ground.dev should then pick up our repository within the hour.

When using Github. To set up a webhook, go to the settings page of your repository or organization. From there, click Webhooks, then Add webhook. Use te following settings:
* Payload URL: https://www.common-ground.dev/webhook/github
* Content type: Application/JSON
* Secret: [leave blanck]
* Events: [just the push event]

Now every time you update your repository the commonground dev page will alerted, rescan your repository and do al the appropriate platform actions. It just as easy as that.
Another option that we have is to declare our repository on [publiccode](), to do this you need to copy the publiccode.yaml from the [api/public/schema](api/public/schema]) folder to your root folder (dont forget to redo this every time you make a change to your repository).


Continues integration
Expand Down
2 changes: 2 additions & 0 deletions api/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ CMD ["php-fpm"]
# Let update the docs to show the latest chages
# RUN bin/console api:swagger:export --output=/srv/api/public/schema/openapi.yaml --yaml --spec-version=3

RUN bin/console app:publiccode:update --location=/srv/api/public/schema/ --spec-version=0.2

#############################
# "nginx" stage #
#############################
Expand Down
2 changes: 1 addition & 1 deletion api/config/packages/api_platform.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ parameters:
env(CONTAINER_PROJECT_NAME): ''
env(CONTAINER_REPRO): ''

api_platform:
api_platform:
mapping:
paths: ['%kernel.project_dir%/src/Entity']

Expand Down
4 changes: 4 additions & 0 deletions api/config/packages/doctrine.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
parameters:
env(DATABASE_URL): 'postgres://api-platform:!ChangeMe!@db/api?serverVersion=10.1'
# Organisation stuff

doctrine:
dbal:
# configure these for your database server
Expand Down
35 changes: 30 additions & 5 deletions api/config/packages/twig.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
parameters:
env(APP_DOMAINS): '[]'
# Organisation stuff
env(GOOGLE_TAG_MANAGER_ID): ''
env(HUBSPOT_EMBED_CODE): ''
env(CONTAINER_REGISTRY_BASE): ''
env(CONTAINER_PROJECT_NAME): ''
env(ORGANIZATION_NAME): ''
env(ORGANIZATION_EMAIL_ADDRESS): ''
env(ORGANIZATION_COUNTRY_NAME): ''
env(ORGANIZATION_STATE): ''
env(ORGANIZATION_LOCALITY): ''
env(ORGANIZATION_EMAIL_ADDRESS): ''
env(ORGANIZATION_COUNTRY_NAME): ''
env(ORGANIZATION_STATE): ''
env(ORGANIZATION_LOCALITY): ''
env(ORGANIZATION_UNIT_NAME): ''
env(APP_NAME): ''
env(APP_TITLE): ''
env(APP_LOGO): ''
env(APP_HOME): ''
env(APP_VERSION): ''
env(APP_ENV): ''
env(APP_DEBUG): ''
env(APP_SUBDOMAIN): ''
env(APP_DOMAINS): '[]'
env(APP_DEMO): ''
env(APP_REPRO): ''
env(APP_DESCRIPTION): ''
env(AUTH_ENABLED): ''
env(AUDITTRAIL_ENABLED): ''
env(NOTIFICATION_ENABLED): ''
env(HEALTH_ENABLED): ''
env(TRUSTED_HOSTS): ''
env(TRUSTED_PROXIES): ''
env(NLX_OUTWAY): ''
env(NLX_INWAY): ''

twig:
default_path: '%kernel.project_dir%/templates'
Expand All @@ -28,6 +51,8 @@ twig:

app_name: '%env(APP_NAME)%'
app_title: '%env(APP_TITLE)%'
app_logo: '%env(APP_LOGO)%'
app_home: '%env(APP_HOME)%'
app_version: '%env(APP_VERSION)%'
app_env: '%env(APP_ENV)%'
app_debug: '%env(APP_DEBUG)%'
Expand Down
6 changes: 5 additions & 1 deletion api/docker/php/docker-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,11 @@ if [ "$1" = 'php-fpm' ] || [ "$1" = 'php' ] || [ "$1" = 'bin/console' ]; then

# this should only be done in an build
echo "Updating Helm charts"
bin/console app:helm:update --location=/srv/api/helm --spec-version=3
bin/console app:helm:update --location=/srv/api/helm --spec-version=3

# this should only be done in an build
echo "Updating publiccode charts"
bin/console app:publiccode:update --location=/srv/api/public/schema/ --spec-version=0.2
fi
fi

Expand Down
4 changes: 2 additions & 2 deletions api/helm/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ appVersion: V.0.1
description: ''Naast deze JSON rest API is er ook een [graphql](/graphql) interface beschikbaar.''
name: pc
version: 0.1.0
home: https://common-ground.dev
icon: https://common-ground.dev/logo-250x250.png
home: pc.zaakonline.nl
icon: pc.zaakonline.nl
115 changes: 115 additions & 0 deletions api/public/schema/publiccode.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
publiccodeYmlVersion: "0.2"

name: pc
applicationSuite: commonground
url: "https://github.com/ConductionNL/Proto-component-commonground"
landingURL: "pc.zaakonline.nl"
isBasedOn: "https://github.com/ConductionNL/Proto-component-commonground.git" softwareVersion: "V.0.1"
releaseDate: "2019-28-12"
logo: pc.zaakonline.nl
monochromeLogo: img/logo-mono.svg

inputTypes:
- application/json
- application/xml

outputTypes:
- application/json
- application/ld+json
- application/hal+json
- application/vnd.api+json
- application/health+json
- application/xml
- application/x-yaml
- text/csv
- text/html

platforms:
- web

categories:
- it-development

usedBy:
- Gemeente Utrecht
- Gemeente Den Haag
- Gemeente Hoorn


roadmap: "https://github.com/ConductionNL/Proto-component-commonground/blob/master/ROADMAP.md"

developmentStatus: development

softwareType: "standalone/other"

#intendedAudience:
# scope:
# - science-and-technology
# countries:
# - it
# - de
# unsupportedCountries:
# - us

description:
en:
# localisedName: Medusa
# genericName: Text Editor
# shortDescription: >
# This description can have a maximum 150
# characters long. We should not fill the
# remaining space with "Lorem Ipsum". End
#
# longDescription: >
# Very long description of this software, also split
# on multiple rows. You should note what the software
# is and why one should need it.

documentation: "https://github.com/ConductionNL/Proto-component-commonground/blob/master/README.md"
apiDocumentation: "pc.zaakonline.nl"
#
# features:
# - Very important feature
# - Will run without a problem
# - Has zero bugs
# - Solves all the problems of the world
# screenshots:
# - img/sshot1.jpg
# - img/sshot2.jpg
# - img/sshot3.jpg
# videos:
# - https://youtube.com/xxxxxxxx
# awards:
# - 1st Price Software of the year

legal:
license: EUPL-1.2
mainCopyrightOwner: Conduction
repoOwner: Conduction
authorsFile: AUTHORS.md

maintenance:
type: "internal"

contractors:
- name: "Conduction B.V"
email: "[email protected]"
website: "https://www.conduction.nl"
until: "2099-01-01"

contacts:
- name: Ruben van der Linde
email: "[email protected]"
affiliation: "Conduction B.V"

localisation:
localisationReady: yes
availableLanguages:
- en
- nl

dependsOn:
open:
- name: Kubernetes
versionMin: "1.15.5-do.1"

71 changes: 71 additions & 0 deletions api/src/Command/PubliccodeCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

// src/Command/CreateUserCommand.php

namespace App\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Exception\InvalidOptionException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Style\SymfonyStyle;
use Twig\Environment;

class PubliccodeCommand extends Command
{
private $twig;

public function __construct(Environment $twig)
{
$this->twig = $twig;

parent::__construct();
}

/**
* {@inheritdoc}
*/
protected function configure()
{
$this
->setName('app:publiccode:update')
// the short description shown while running "php bin/console list"
->setDescription('Creates a new public chart.')

// the full command description shown when running the command with
// the "--help" option
->setHelp('see ehttps://github.com/italia/publiccode.yml')
->setDescription('Publiccode.yml is a metadata standard for repositories containing software developed or acquired by the Public Administration, aimed at making them easily discoverabile and thus reusable by other entities.By including a publiccode.yml file in the root of a repository, and populating it with information about the software, technicians and civil servants can evaluate it. Automatic indexing tools can also be built, since the format is easily readable by both humans and machines.')
->addOption('location', null, InputOption::VALUE_OPTIONAL, 'Write output to files in the given location', '/srv/api/public/schema/')
->addOption('spec-version', null, InputOption::VALUE_OPTIONAL, 'Publiccode version to use ("0.1.0")', '0.1.0');
}

/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$io = new SymfonyStyle($input, $output);
/** @var string $version */
$version = $input->getOption('spec-version');

//if (!\in_array($version, ['0.1.0'], true)) {
// throw new InvalidOptionException(sprintf('This tool only supports version 2 and 3 of the OpenAPI specification ("%s" given).', $version));
//}

$publiccode = $this->twig->render('publiccode/publiccode.yaml.twig');

if (!empty($location = $input->getOption('location')) && \is_string($location)) {
file_put_contents($location.'/publiccode.yaml', $publiccode);
$io->success(sprintf('Data written to %s/publiccode.yaml (specification version %s).', $location, $version));
} else {
// outputs multiple lines to the console (adding "\n" at the end of each line)
$output->writeln([
'Publiccode Chart',
'============',
$chart,
]);
}
}
}
19 changes: 12 additions & 7 deletions api/src/Subscriber/FieldsAndExtendSubscriber.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public static function getSubscribedEvents()

public function FilterFields(GetResponseForControllerResultEvent $event)
{
/* @todo Contains a bug
$result = $event->getControllerResult();
$fields = $event->getRequest()->query->get('fields');
$extends = $event->getRequest()->query->get('extend');
Expand All @@ -41,6 +42,12 @@ public function FilterFields(GetResponseForControllerResultEvent $event)
$contentType= $event->getRequest()->headers->get('Accept');
}
// Only do somthing if fields is query supplied
if (!$fields && !$extends) {
return $result;
}
// This needs to be bassed on the content-type
// Lets set a return content type
Expand All @@ -58,11 +65,6 @@ public function FilterFields(GetResponseForControllerResultEvent $event)
$contentType = 'application/json';
$renderType = "json";
}

// Only do somthing if fields is query supplied
if (!$fields && $extends) {
return $result;
}
// let turn fields into an array if it isn't one already
if (!is_array($fields)) {
Expand All @@ -73,7 +75,7 @@ public function FilterFields(GetResponseForControllerResultEvent $event)
}
// Its possible to nest fields for filterins
foreach($fields as $key->$value){
foreach($fields as $key=>$value){
// Lets check if the fields contain one or more .'s
if (strpos($value, '.') !== false) {
// This is where it gets complicated couse it could go on indevinitly
Expand Down Expand Up @@ -101,9 +103,10 @@ public function FilterFields(GetResponseForControllerResultEvent $event)
$jsonArray = json_decode($json, true);
// The we want to extend properties from the extend query
foreach($extends as $extend){
/* @todo add security checks */
// @todo add security checks
// Get new object for the extend
$extendObject = $this->propertyAccessor->getValue($result, $extend);
// turn to json
Expand All @@ -117,6 +120,7 @@ public function FilterFields(GetResponseForControllerResultEvent $event)
$jsonArray[$extend] = json_decode($extendjson, true);
}
$json = json_encode($jsonArray);
$response = new Response(
Expand All @@ -126,5 +130,6 @@ public function FilterFields(GetResponseForControllerResultEvent $event)
);
$event->setResponse($response);
*/
}
}
4 changes: 2 additions & 2 deletions api/templates/helm/Chart.yaml.twig
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ appVersion: {{ app_version }}
description: '{{ app_description }}'
name: {{ app_name|replace({' ': ''})|lower }}
version: 0.1.0
home: https://common-ground.dev
icon: https://common-ground.dev/logo-250x250.png
home: {{ app_home }}
icon: {{ app_logo }}
Loading

0 comments on commit 2531b6a

Please sign in to comment.