Skip to content

Commit

Permalink
Merge branch 'master' into test_priceinfo_mhlee_240124
Browse files Browse the repository at this point in the history
  • Loading branch information
SungWoongz authored Feb 28, 2024
2 parents 83f2f2b + b09b937 commit 7a92bec
Show file tree
Hide file tree
Showing 71 changed files with 2,863 additions and 1,125 deletions.
87 changes: 87 additions & 0 deletions .github/workflows/korean-checker-post-comment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# This workflow will make a comment on the pull request
# about the part where Korean was found.
name: Post handler of korean checker
on:
workflow_run:
workflows: ["Korean checker"]
types:
- completed

env:
ARTIFACT_NAME: results-to-check-korean
FILE_KOREAN_CHECKING_RESULT: "korean-check-results.md"
FILE_REPORT: "checking-report.md"

jobs:
make-comment-on-the-pr:
name: Make a comment on the PR

runs-on: ubuntu-latest
if: >
github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success'
# Permissions for the GITHUB_TOKEN
# Ref. https://docs.github.com/en/actions/security-guides/automatic-token-authentication#permissions-for-the-github_token
permissions:
# issues: write
pull-requests: write
actions: read

steps:
- name: Download results
uses: actions/download-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
github-token: ${{ secrets.GITHUB_TOKEN }}
run-id: ${{ github.event.workflow_run.id }}

- name: Display structure of downloaded files for debugging
shell: bash
run: ls -R

- name: Make a report
shell: bash
run: |
REPORT="${FILE_REPORT}"
if [ -s "${FILE_KOREAN_CHECKING_RESULT}" ]; then
echo "(DEBUG) Korean texts are detected."
echo "**Could you please check and revise Korean texts?**" > $REPORT
echo "Note - All output of print and log statements should be in English. :wink:" >> $REPORT
echo "" >> $REPORT
cat "${FILE_KOREAN_CHECKING_RESULT}" >> "$REPORT"
else
echo "(DEBUG) No Korean texts are detected."
echo "Good news! All print and log statements are in English, as per our guidelines. :blush:" > $REPORT
fi
- name: Comment PR with results
uses: actions/github-script@v7
with:
github-token: ${{secrets.GITHUB_TOKEN}}
script: |
const fs = require('fs');
const path = require('path');
// Read PR number
const prNumberPath = path.join(process.env.GITHUB_WORKSPACE, 'pr-number.txt');
let prNumber = '';
if (fs.existsSync(prNumberPath)) {
prNumber = fs.readFileSync(prNumberPath, 'utf8').trim();
}
// Read results to check Korean
const resultsPath = path.join(process.env.GITHUB_WORKSPACE, '${{env.FILE_REPORT}}');
if (fs.existsSync(resultsPath)) {
const results = fs.readFileSync(resultsPath, 'utf8');
if (results.trim().length > 0 && prNumber.length > 0) {
github.rest.issues.createComment({
issue_number: parseInt(prNumber, 10),
owner: context.repo.owner,
repo: context.repo.repo,
body: results
});
}
}
124 changes: 124 additions & 0 deletions .github/workflows/korean-checker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
name: Korean checker

# Controls/triggers when the action will run.
on:
pull_request:
branches:
- 'master'
paths:
- '**.go'

# Environment variables
env:
OUTPUT_DIR: "./output"
OUTPUT_FILE: "korean-check-results.md"

jobs:
check-if-Korean-is-included:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0 # Fetch all history for all branches and tags

- name: Setup to check Korean and upload the results
run: |
# Make an output directory
if [[ ! -e $OUTPUT_DIR ]]; then
mkdir -p $OUTPUT_DIR
elif [[ ! -d $OUTPUT_DIR ]]; then
echo "$OUTPUT_DIR already exists but is not a directory" 1>&2
fi
echo ${{ github.event.number }} > ${OUTPUT_DIR}/pr-number.txt
- name: Check Korean in quotes
id: check-korean
run: |
set -x
##### DEBUG section, this will be removed later ###########
ls -al
git status
git branch
# Default environment variables
BASE_BRANCH="origin/${{github.base_ref}}" # origin/master
PR_BRANCH=${GITHUB_REF#refs/} # pull/xx/merge
echo "Base branch: ${BASE_BRANCH}"
echo "Extract branch: ${GITHUB_REF#refs/}"
# `github` context information
echo "(DEBUG) github.ref: ${{github.ref}}"
echo "(DEBUG) github.head_ref: ${{github.head_ref}}"
echo "(DEBUG) github.base_ref: ${{github.base_ref}}"
#####################################################
temp_output="temp.md"
OUTPUT="${OUTPUT_DIR}/${OUTPUT_FILE}"
# Get changed files in the PR
files=$(git diff --name-only ${BASE_BRANCH}...${PR_BRANCH} | grep '\.go$')
# Create a temp file
echo "" > $temp_output
# Process each changed file
for file in $files; do
found_korean=false
# Extract changed lines
changed_lines=$(git diff ${BASE_BRANCH}...${PR_BRANCH} -- $file | grep "^+")
echo "(DEBUG) Changed lines in $file:"
echo "$changed_lines"
# Check Korean characters wrapped in quote (" ")
korean_lines=$(echo "$changed_lines" | grep -n -P "\"([^\"]*[\x{AC00}-\x{D7A3}]+[^\"]*)\"" || true)
# Check all Korean characters, such as Korean wrapped in quote, included in comments, and so on.
# korean_lines=$(echo "$changed_lines" | grep -n -P "[\x{AC00}-\x{D7A3}]" || true)
echo "(DEBUG) Korean lines in $file:"
echo "$korean_lines"
if [ -n "$korean_lines" ]; then
echo "**$file**" >> $temp_output
echo "\`\`\`diff" >> $temp_output
echo "$korean_lines" | sed -e 's/^[+]\s*//' >> $temp_output
echo "\`\`\`" >> $temp_output
echo "" >> $temp_output
fi
done
# Output the results to check if Korean exists
# Check if the temp_output exists and has content
if [ -s "$temp_output" ]; then
# Trim before checking if the file has content
trimmed_temp_outputs=$(cat "$temp_output" | xargs)
echo "(DEBUG) Trimmed temp_output:"
echo "$trimmed_temp_outputs"
if [ -n "$trimmed_temp_outputs" ]; then
echo "(DEBUG) Korean content detected."
cat "$temp_output" > "$OUTPUT"
# echo "KOREAN_EXISTS=true" >> $GITHUB_OUTPUT
else
echo "(DEBUG) No Korean content detected."
# echo "KOREAN_EXISTS=false" >> $GITHUB_OUTPUT
fi
fi
- name: Upload Korean check results
# if: steps.check-korean.outputs.KOREAN_EXISTS == 'true'
uses: actions/upload-artifact@v4
with:
name: results-to-check-korean
path: ${{ env.OUTPUT_DIR }}

# - name: Fail on Korean Content
# if: steps.check-korean.outputs.KOREAN_EXISTS == 'true'
# run: |
# echo "Korean content detected. Failing the workflow on purpose."
# exit 1

# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/
# https://github.com/actions/upload-artifact
# https://github.com/actions/download-artifact
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ cloud-driver-libs/.securitygroup-kt/*
vendor/*
cloud-driver-libs/*.so
meta_db/*
cache/*
api-runtime/rest-runtime/~/go/src/github.com/cloud-barista/cb-spider/meta_db/dat/*
conf/store_conf.yaml
cloud-control-manager/cloud-driver/drivers/aws/main/log/cblogs.log
Expand Down
8 changes: 3 additions & 5 deletions api-runtime/common-runtime/CommonManager.go
Original file line number Diff line number Diff line change
Expand Up @@ -720,18 +720,16 @@ func ListAllResource(connectionName string, rsType string) (AllResourceList, err
// (3) filtering CSP-list by IID-list
MappedList := []*cres.IID{}
OnlySpiderList := []*cres.IID{}
for _, iidInfo := range iidList {
for _, userIId := range iidList { // iidList has already userIId
exist := false
for _, iid := range iidCSPList {
userIId := makeUserIID(iidInfo.NameId, iidInfo.SystemId)
if userIId.SystemId == iid.SystemId {
MappedList = append(MappedList, &userIId)
MappedList = append(MappedList, userIId)
exist = true
}
}
if !exist {
userIId := makeUserIID(iidInfo.NameId, iidInfo.SystemId)
OnlySpiderList = append(OnlySpiderList, &userIId)
OnlySpiderList = append(OnlySpiderList, userIId)
}
}

Expand Down
128 changes: 128 additions & 0 deletions api-runtime/common-runtime/RegionZoneHandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,3 +157,131 @@ func ListOrgZone(connectionName string) (string, error) {

return info, nil
}

// ================ RegionZone Handler (Pre-Config Version)

func ListRegionZonePreConfig(driverName string, credentialName string) ([]*cres.RegionZoneInfo, error) {
cblog.Info("call ListRegionZonePreConfig()")

// check empty and trim user inputs
driverName, err := EmptyCheckAndTrim("driverName", driverName)
if err != nil {
cblog.Error(err)
return nil, err
}
credentialName, err = EmptyCheckAndTrim("credentialName", credentialName)
if err != nil {
cblog.Error(err)
return nil, err
}

cldConn, err := ccm.GetCloudConnectionByDriverNameAndCredentialName(driverName, credentialName)
if err != nil {
cblog.Error(err)
return nil, err
}

handler, err := cldConn.CreateRegionZoneHandler()
if err != nil {
cblog.Error(err)
return nil, err
}

infoList, err := handler.ListRegionZone()
if err != nil {
cblog.Error(err)
return nil, err
}

if infoList == nil || len(infoList) <= 0 {
infoList = []*cres.RegionZoneInfo{}
}

// Set KeyValueList to an empty array if it is nil
for _, region := range infoList {
if region.KeyValueList == nil {
region.KeyValueList = []cres.KeyValue{}
}
}

return infoList, nil
}

func GetRegionZonePreConfig(driverName string, credentialName string, nameID string) (*cres.RegionZoneInfo, error) {
cblog.Info("call GetRegionZonePreConfig()")

driverName, err := EmptyCheckAndTrim("driverName", driverName)
if err != nil {
cblog.Error(err)
return nil, err
}
credentialName, err = EmptyCheckAndTrim("credentialName", credentialName)
if err != nil {
cblog.Error(err)
return nil, err
}
nameID, err = EmptyCheckAndTrim("nameID", nameID)
if err != nil {
cblog.Error(err)
return nil, err
}

cldConn, err := ccm.GetCloudConnectionByDriverNameAndCredentialName(driverName, credentialName)
if err != nil {
cblog.Error(err)
return nil, err
}

handler, err := cldConn.CreateRegionZoneHandler()
if err != nil {
cblog.Error(err)
return nil, err
}
info, err := handler.GetRegionZone(nameID)
if err != nil {
cblog.Error(err)
return nil, err
}

// Set KeyValueList to an empty array if it is nil
if info.KeyValueList == nil {
info.KeyValueList = []cres.KeyValue{}
}

return &info, nil
}

func ListOrgRegionPreConfig(driverName string, credentialName string) (string, error) {
cblog.Info("call ListOrgRegionPreConfig()")

driverName, err := EmptyCheckAndTrim("driverName", driverName)
if err != nil {
cblog.Error(err)
return "", err
}
credentialName, err = EmptyCheckAndTrim("credentialName", credentialName)
if err != nil {
cblog.Error(err)
return "", err
}

cldConn, err := ccm.GetCloudConnectionByDriverNameAndCredentialName(driverName, credentialName)
if err != nil {
cblog.Error(err)
return "", err
}

handler, err := cldConn.CreateRegionZoneHandler()
if err != nil {
cblog.Error(err)
return "", err
}

infoList, err := handler.ListOrgRegion()
if err != nil {
cblog.Error(err)
return "", err
}

return infoList, nil
}
6 changes: 6 additions & 0 deletions api-runtime/rest-runtime/CBSpiderRuntime.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,10 @@ func RunServer() {
{"GET", "/regionzone/:Name", GetRegionZone},
{"GET", "/orgregion", ListOrgRegion},
{"GET", "/orgzone", ListOrgZone},
// by driverName & credentialName
{"GET", "/preconfig/regionzone", ListRegionZonePreConfig},
{"GET", "/preconfig/regionzone/:Name", GetRegionZonePreConfig},
{"GET", "/preconfig/orgregion", ListOrgRegionPreConfig},

//----------PriceInfo Handler
{"GET", "/productfamily/:RegionName", ListProductFamily},
Expand Down Expand Up @@ -445,6 +449,8 @@ func RunServer() {

{"GET", "/adminweb/priceinfo/:ConnectConfig", aw.PriceInfoRequest},
{"GET", "/adminweb/priceinfotablelist/:ProductFamily/:RegionName/:ConnectConfig", aw.PriceInfoTableList},
// download price info with JSON file
{"GET", "/adminweb/priceinfo/download/:FileName", aw.DownloadPriceInfo},

{"GET", "/adminweb/cluster/:ConnectConfig", aw.Cluster},
{"GET", "/adminweb/clustermgmt/:ConnectConfig", aw.ClusterMgmt},
Expand Down
Loading

0 comments on commit 7a92bec

Please sign in to comment.