|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Copyright 2018 Oracle and/or its affiliates. All rights reserved. |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +# Utility functions for working with the CCM's Wercker CI. |
| 18 | + |
| 19 | +# Functions ******************************************************************* |
| 20 | +# |
| 21 | + |
| 22 | +function _check_var() { |
| 23 | + local name=$1 |
| 24 | + if [ -z ${!name} ]; then |
| 25 | + echo "WARNING: '""$name""' is required." |
| 26 | + fi |
| 27 | +} |
| 28 | + |
| 29 | +# Check the required environnment variables are set when generating a |
| 30 | +# 'cloud-provider.yaml' file. |
| 31 | +function _check_vars() { |
| 32 | + _check_var OCI_REGION |
| 33 | + _check_var OCI_TENANCY |
| 34 | + _check_var OCI_COMPARTMENT |
| 35 | + _check_var OCI_USER |
| 36 | + _check_var FINGERPRINT |
| 37 | + _check_var PRIVATE_KEY |
| 38 | + _check_var OCI_SUBNET_01 |
| 39 | + _check_var OCI_SUBNET_02 |
| 40 | +} |
| 41 | + |
| 42 | +# Generate a 'cloud-provider.yaml' file for use in CCM deployment and |
| 43 | +# e2e testing. |
| 44 | +function generate-cloud-provider-config() { |
| 45 | + local file=${1:-"./cloud-provider.yaml"} |
| 46 | + _check_vars |
| 47 | + cat > $file <<EOF |
| 48 | +auth: |
| 49 | + region: $OCI_REGION |
| 50 | + tenancy: $OCI_TENANCY |
| 51 | + compartment: $OCI_COMPARTMENT |
| 52 | + user: $OCI_USER |
| 53 | + key: | |
| 54 | + $PRIVATE_KEY |
| 55 | + fingerprint: $FINGERPRINT |
| 56 | +loadBalancer: |
| 57 | + disableSecurityListManagement: false |
| 58 | + subnet1: $OCI_SUBNET_01 |
| 59 | + subnet2: $OCI_SUBNET_02 |
| 60 | +EOF |
| 61 | +} |
| 62 | + |
| 63 | +# The Wercker CI platform requires configuration files are base64 encoded. |
| 64 | +function base64_encode() { |
| 65 | + local input=$1 |
| 66 | + local output=${2:-encoded} |
| 67 | + cat $input | openssl enc -base64 -A > $output |
| 68 | +} |
| 69 | + |
| 70 | +function base64_decode() { |
| 71 | + local input=$1 |
| 72 | + local output=${2:-decoded} |
| 73 | + cat $input | openssl enc -base64 -d -A > $output |
| 74 | +} |
| 75 | + |
| 76 | +# If provided, execute the specified function. |
| 77 | +if [ ! -z "$1" ]; then |
| 78 | + $1 |
| 79 | +else |
| 80 | + generate-cloud-provider-config |
| 81 | +fi |
0 commit comments