/*
 *
 * K2HR3 Web Application
 *
 * Copyright 2017 Yahoo Japan Corporation.
 *
 * K2HR3 is K2hdkc based Resource and Roles and policy Rules, gathers
 * common management information for the cloud.
 * K2HR3 can dynamically manage information as "who", "what", "operate".
 * These are stored as roles, resources, policies in K2hdkc, and the
 * client system can dynamically read and modify these information.
 *
 * For the full copyright and license information, please view
 * the license file that was distributed with this source code.
 *
 * AUTHOR:   Takeshi Nakatani
 * CREATE:   Wed Sep 6 2017
 * REVISION:
 *
 */

//
// Default(base) configuration file by json for config
//

// [NOTE]
// The userdata used by k2hr3 is include file format type.
// This userdata is multi-line and has the url and path for including expanded multipart userdata.
// Then userdata value is simple template which is filled by k2hr3 for each role/user.
// The following template's value is used:
//	{{= %K2HR3_API_HOST_URI% }}				: K2HR3 API host and uri which is made from "apihost"
//	{{= %K2HR3_USERDATA_INCLUDE_PATH% }}	: Getting compressed user data script url path
//	{{= %K2HR3_ROLETOKEN_IN_SECRET% }}		: Replacing base64 encoded role token string
//	{{= %K2HR3_ROLETOKEN_RAW% }}			: Replacing raw role token string
//	{{= %K2HR3_ROLEYRN_IN_SIDECAR% }}		: Replacing role full yrn path string
//	{{= %K2HR3_REST_API_HOST% }}			: Replacing k2hr3-k8s-init.sh host/port/schema parameter

//
// [KEY-VALUE]
//	scheme							: F/E server scheme(http or https)
//	port							: F/E server port
//	multiproc						: flag for  multi process of F/E servers
//	runuser							: user name for F/E server process
//	privatekey						: Private key file for HTTPS
//	cert							: Certification file for HTTPS
//	validator						: user validator object type
//	uselocaltenant					: use Local Tenant
//	lang							: Language
//	apischeme						: API server scheme(http or https) for accessing React
//	apihost							: API server hostname for accessing React
//	apiport							: API server port for accessing React
//	appmenu							: Application menu list on React
//	userdata						: User Data Script
//	secretyaml						: Secret Yaml
//	sidecaryaml						: Sidecar Yaml
//
{
	'scheme':			'http',
	'port':				3000,
	'multiproc':		true,
	'runuser':			'',
	'privatekey':		'',
	'cert':				'',
	'ca':				'',
	'validator':		'userValidateCredential',
	'uselocaltenant':	true,
	'lang':				'en',

	'logdir':			'log',
	'accesslogname':	'access.log',
	'consolelogname':	'error.log',
	'logrotateopt': {
		'compress':			'gzip',
		'interval':			'6h',
		'initialRotation':	true
	},

	'apischeme':		'http',
	'apihost':			'localhost',
	'apiport':			3001,

	'appmenu': [
		{
			'name':		'Document',
			'url':		'https://k2hr3.antpick.ax/'
		},
		{
			'name':		'Support',
			'url':		'https://github.com/yahoojapan/k2hr3_app/issues'
		}
	],

	'userdata':			'\
#include\n\
{{= %K2HR3_API_HOST_URI% }}/v1/userdata/{{= %K2HR3_USERDATA_INCLUDE_PATH% }}\n\
',
	'secretyaml':		'\
apiVersion: v1\n\
kind: Secret\n\
metadata:\n\
  name: k2hr3-secret\n\
  namespace: <input your name space>\n\
type: Opaque\n\
data:\n\
  K2HR3_ROLETOKEN: {{= %K2HR3_ROLETOKEN_IN_SECRET% }}\n\
',
	'sidecaryaml':		'\
apiVersion: v1\n\
kind: Pod\n\
metadata:\n\
  labels:\n\
    labelName: <label>\n\
  name: <name>\n\
spec:\n\
  #------------------------------------------------------------\n\
  # K2HR3 Sidecar volume - start\n\
  #------------------------------------------------------------\n\
  volumes:\n\
  - name: k2hr3-volume\n\
    hostPath:\n\
      path: /k2hr3-data\n\
      type: DirectoryOrCreate\n\
  #------------------------------------------------------------\n\
  # K2HR3 Sidecar volume - end\n\
  #------------------------------------------------------------\n\
  containers:\n\
    - name: <your container>\n\
      image: <your image>\n\
      volumeMounts:\n\
      - mountPath: /k2hr3-volume\n\
        name: k2hr3-volume\n\
      command:\n\
        - <your command...>\n\
    #--------------------------------------------------------------------------\n\
    # K2HR3 Sidecar - start\n\
    #--------------------------------------------------------------------------\n\
    - name: k2hr3-sidecar\n\
      image: docker.io/antpickax/k2hr3.sidecar:0.1\n\
      envFrom:\n\
      - secretRef:\n\
          name: k2hr3-secret\n\
      env:\n\
        - name: K2HR3_NODE_NAME\n\
          valueFrom:\n\
            fieldRef:\n\
              fieldPath: spec.nodeName\n\
        - name: K2HR3_POD_NAME\n\
          valueFrom:\n\
            fieldRef:\n\
              fieldPath: metadata.name\n\
        - name: K2HR3_POD_NAMESPACE\n\
          valueFrom:\n\
            fieldRef:\n\
              fieldPath: metadata.namespace\n\
        - name: K2HR3_POD_IP\n\
          valueFrom:\n\
            fieldRef:\n\
              fieldPath: status.podIP\n\
        - name: K2HR3_POD_SERVICE_ACCOUNT\n\
          valueFrom:\n\
            fieldRef:\n\
              fieldPath: spec.serviceAccountName\n\
        - name: K2HR3_NODE_IP\n\
          valueFrom:\n\
            fieldRef:\n\
              fieldPath: status.hostIP\n\
        - name: K2HR3_POD_ID\n\
          valueFrom:\n\
            fieldRef:\n\
              fieldPath: metadata.uid\n\
      volumeMounts:\n\
      - mountPath: /k2hr3-volume\n\
        name: k2hr3-volume\n\
      command:\n\
        - sh\n\
        - -c\n\
        - "while true; do sleep 30; done"\n\
      lifecycle:\n\
        postStart:\n\
          exec:\n\
            command:\n\
              - sh\n\
              - -c\n\
              - "/usr/local/bin/k2hr3-k8s-init.sh -reg -rtoken ${K2HR3_ROLETOKEN} -role {{= %K2HR3_ROLEYRN_IN_SIDECAR% }} {{= %K2HR3_REST_API_HOST% }}"\n\
        preStop:\n\
          exec:\n\
            command:\n\
              - sh\n\
              - -c\n\
              - "/usr/local/bin/k2hr3-k8s-init.sh -del -role {{= %K2HR3_ROLEYRN_IN_SIDECAR% }} {{= %K2HR3_REST_API_HOST% }}"\n\
    #--------------------------------------------------------------------------\n\
    # K2HR3 Sidecar - end\n\
    #--------------------------------------------------------------------------\n\
',
	'crcobj': {
		'Test custom registration code': {
			'CRC_K2HR3_API_HOST_URI':			'{{= %K2HR3_API_HOST_URI% }}',
			'CRC_K2HR3_USERDATA_INCLUDE_PATH':	'{{= %K2HR3_USERDATA_INCLUDE_PATH% }}',
			'CRC_K2HR3_ROLETOKEN_IN_SECRET':	'{{= %K2HR3_ROLETOKEN_IN_SECRET% }}',
			'CRC_K2HR3_ROLETOKEN_RAW':			'{{= %K2HR3_ROLETOKEN_RAW% }}',
			'CRC_K2HR3_ROLEYRN_IN_SIDECAR':		'{{= %K2HR3_ROLEYRN_IN_SIDECAR% }}'
		}
	}
}

/*
 * Local variables:
 * tab-width: 4
 * c-basic-offset: 4
 * End:
 * vim600: noexpandtab sw=4 ts=4 fdm=marker
 * vim<600: noexpandtab sw=4 ts=4
 */
