From 053961489228f49a59f7462622cb4852506f00c1 Mon Sep 17 00:00:00 2001 From: "St. Lawrence, Zachary" Date: Fri, 31 Jul 2020 17:13:30 -0400 Subject: [PATCH 01/16] Fixed git ignore to better exclude ide classes and configs --- .gitignore | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 90f67db8..a793d080 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,16 @@ +# go dependencies vendor/ -.idea + +# testing and custom build code +*.log + +# eclipse +.classpath +.project +.settings + +# IntelliJ +/.idea/ +*.ipr +*.iws *.iml \ No newline at end of file From 19df3a2a96f14a8fb60fdf129135b3abd5ab51fc Mon Sep 17 00:00:00 2001 From: "Piotrowski, Piotr" Date: Thu, 13 Aug 2020 11:31:46 +0200 Subject: [PATCH 02/16] [TFP-75][Change] Return nil instead of error if no cp code was found --- papi-v1/cpcodes.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/papi-v1/cpcodes.go b/papi-v1/cpcodes.go index 9afe4192..7158513a 100644 --- a/papi-v1/cpcodes.go +++ b/papi-v1/cpcodes.go @@ -127,7 +127,7 @@ func (cpcodes *CpCodes) FindCpCode(nameOrId string, correlationid string) (*CpCo return nil, err } if len(cpcodes.CpCodes.Items) == 0 { - return nil, fmt.Errorf("unable to fetch CP codes for group/contract") + return nil, nil } } From 3570a4b4d705fc206ed98a3b4cc2bb0506ca760b Mon Sep 17 00:00:00 2001 From: "St. Lawrence, Zachary" Date: Wed, 26 Aug 2020 11:18:40 -0400 Subject: [PATCH 03/16] TFP-9 Akamai build process updates. Added pom for automated CI. Added semtag for semantic tagging. Updated gitignore to ignore build artifacts. Finally linted code to fix basic format issues. --- .gitignore | 16 +- configgtm-v1_4/datacenter.go | 2 +- papi-v1/activations.go | 4 +- papi-v1/available.go | 2 +- papi-v1/client_settings.go | 2 +- papi-v1/custombehaviors.go | 2 +- papi-v1/customoverrides.go | 2 +- pom.xml | 114 ++++++ reportsgtm-v1/datacenter_test.go | 2 +- reportsgtm-v1/property_test.go | 2 +- reportsgtm-v1/util.go | 18 +- scripts/semtag | 626 +++++++++++++++++++++++++++++++ 12 files changed, 769 insertions(+), 23 deletions(-) create mode 100644 pom.xml create mode 100755 scripts/semtag diff --git a/.gitignore b/.gitignore index a793d080..16982856 100644 --- a/.gitignore +++ b/.gitignore @@ -1,9 +1,14 @@ -# go dependencies -vendor/ - # testing and custom build code *.log +# local files +.DS_Store +/dist + +# vscode +.vscode/ +_debug_bin + # eclipse .classpath .project @@ -13,4 +18,7 @@ vendor/ /.idea/ *.ipr *.iws -*.iml \ No newline at end of file +*.iml + +# go dependencies +vendor/ \ No newline at end of file diff --git a/configgtm-v1_4/datacenter.go b/configgtm-v1_4/datacenter.go index 0214dc79..c7e39c44 100644 --- a/configgtm-v1_4/datacenter.go +++ b/configgtm-v1_4/datacenter.go @@ -1,9 +1,9 @@ package configgtm import ( - "github.com/akamai/AkamaiOPEN-edgegrid-golang/client-v1" "errors" "fmt" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/client-v1" "strconv" "strings" ) diff --git a/papi-v1/activations.go b/papi-v1/activations.go index 7d702a78..a0e145d6 100644 --- a/papi-v1/activations.go +++ b/papi-v1/activations.go @@ -7,8 +7,7 @@ import ( "time" "github.com/akamai/AkamaiOPEN-edgegrid-golang/client-v1" - edge "github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid" - + edge "github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid" ) // Activations is a collection of property activations @@ -320,7 +319,6 @@ func (activation *Activation) Save(property *Property, acknowledgeWarnings bool) return err } - edge.PrintHttpResponse(res, true) activations := NewActivations() diff --git a/papi-v1/available.go b/papi-v1/available.go index d63bb8af..fbe946c0 100644 --- a/papi-v1/available.go +++ b/papi-v1/available.go @@ -4,8 +4,8 @@ import ( "fmt" "io/ioutil" - edge "github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid" "github.com/akamai/AkamaiOPEN-edgegrid-golang/client-v1" + edge "github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid" "github.com/xeipuuv/gojsonschema" ) diff --git a/papi-v1/client_settings.go b/papi-v1/client_settings.go index 77475ccf..38f31aaf 100644 --- a/papi-v1/client_settings.go +++ b/papi-v1/client_settings.go @@ -2,7 +2,7 @@ package papi import ( "github.com/akamai/AkamaiOPEN-edgegrid-golang/client-v1" - edge "github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid" + edge "github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid" ) // ClientSettings represents the PAPI client settings resource diff --git a/papi-v1/custombehaviors.go b/papi-v1/custombehaviors.go index 042c75a4..0c118508 100644 --- a/papi-v1/custombehaviors.go +++ b/papi-v1/custombehaviors.go @@ -4,8 +4,8 @@ import ( "fmt" "time" - edge "github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid" "github.com/akamai/AkamaiOPEN-edgegrid-golang/client-v1" + edge "github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid" ) // CustomBehaviors represents a collection of Custom Behaviors diff --git a/papi-v1/customoverrides.go b/papi-v1/customoverrides.go index 6fe1a572..7266e3db 100644 --- a/papi-v1/customoverrides.go +++ b/papi-v1/customoverrides.go @@ -4,8 +4,8 @@ import ( "fmt" "time" - edge "github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid" "github.com/akamai/AkamaiOPEN-edgegrid-golang/client-v1" + edge "github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid" ) // CustomOverrides represents a collection of Custom Overrides diff --git a/pom.xml b/pom.xml new file mode 100644 index 00000000..768a075e --- /dev/null +++ b/pom.xml @@ -0,0 +1,114 @@ + + 4.0.0 + com.akamai.fee + akamaiopen-edgegrid-golang + mvn-golang + 1.0-SNAPSHOT + akamai edgegrid golang + + + + com.akamai + luna + 1.7 + + + + + none + + + UTF-8 + true + true + + + 1.4 + 2.3.4 + 3.0.0 + 1.0.0 + + + + + + primary-akamai-nexus + https://lunabuild.akamai.com/nexus/content/groups/public/ + + true + daily + + + + + + + ${basedir}${file.separator} + ${basedir}${file.separator}dist + akamaiopen-edgegrid-golang + + + com.igormaznitsa + mvn-golang-wrapper + ${mvn-golang-wrapper-plugin.version} + true + + + + install + + + true + + + + + github.com/akamai/AkamaiOPEN-edgegrid-golang + + + + + + + + + org.codehaus.mojo + buildnumber-maven-plugin + ${buildnumber-maven-plugin.version} + + + validate + + create + + + + + lastgitcommit + false + false + unknown + + + + + org.codehaus.mojo + properties-maven-plugin + ${properties-maven-plugin.version} + + dist/build.properties + + + + generate-resources + + write-project-properties + + + + + + + + diff --git a/reportsgtm-v1/datacenter_test.go b/reportsgtm-v1/datacenter_test.go index fb954d0c..b470d6b4 100644 --- a/reportsgtm-v1/datacenter_test.go +++ b/reportsgtm-v1/datacenter_test.go @@ -3,8 +3,8 @@ package reportsgtm import ( "testing" - "gopkg.in/h2non/gock.v1" "github.com/stretchr/testify/assert" + "gopkg.in/h2non/gock.v1" ) // Verify GetTrafficPerDatacenter. diff --git a/reportsgtm-v1/property_test.go b/reportsgtm-v1/property_test.go index c4eed8e2..36cd458b 100644 --- a/reportsgtm-v1/property_test.go +++ b/reportsgtm-v1/property_test.go @@ -3,8 +3,8 @@ package reportsgtm import ( "testing" - "gopkg.in/h2non/gock.v1" "github.com/stretchr/testify/assert" + "gopkg.in/h2non/gock.v1" ) // diff --git a/reportsgtm-v1/util.go b/reportsgtm-v1/util.go index d1697aad..a67977be 100644 --- a/reportsgtm-v1/util.go +++ b/reportsgtm-v1/util.go @@ -84,9 +84,9 @@ func getWindowCore(hostURL string) (*WindowResponse, error) { if client.IsError(res) { if res.StatusCode == 400 { - // Get the body. Could be bad dates. - var windRespErrBody map[string]interface{} - err = client.BodyJSON(res, windRespErrBody) + // Get the body. Could be bad dates. + var windRespErrBody map[string]interface{} + err = client.BodyJSON(res, windRespErrBody) if err != nil { return nil, err } @@ -94,16 +94,16 @@ func getWindowCore(hostURL string) (*WindowResponse, error) { if availEnd, ok := windRespErrBody["availableEndDate"]; ok { stat.End = availEnd.(string) } - if availStart, ok := windRespErrBody["availableStartDate"]; ok { + if availStart, ok := windRespErrBody["availableStartDate"]; ok { stat.Start = availStart.(string) } if stat.End == "" || stat.Start == "" { - cErr := configgtm.CommonError{} - cErr.SetItem("entityName", "Window") - cErr.SetItem("name", "Data Window") + cErr := configgtm.CommonError{} + cErr.SetItem("entityName", "Window") + cErr.SetItem("name", "Data Window") cErr.SetItem("apiErrorMessage", "No available data window") - return nil, cErr - } + return nil, cErr + } } else if res.StatusCode == 404 { cErr := configgtm.CommonError{} cErr.SetItem("entityName", "Window") diff --git a/scripts/semtag b/scripts/semtag new file mode 100755 index 00000000..3a0d6003 --- /dev/null +++ b/scripts/semtag @@ -0,0 +1,626 @@ +#!/usr/bin/env bash +# this file has semantic versioning script from https://github.com/pnikosis/semtag + +PROG=semtag +PROG_VERSION="v0.1.0" + +SEMVER_REGEX="^v?(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(\-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?(\+[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$" +IDENTIFIER_REGEX="^\-([0-9A-Za-z-]+)\.([0-9A-Za-z-]+)*$" + +# Global variables +FIRST_VERSION="v0.0.0" +finalversion=$FIRST_VERSION +lastversion=$FIRST_VERSION +hasversiontag="false" +scope="patch" +displayonly="false" +forcetag="false" +forcedversion= +versionname= +identifier= + +HELP="\ +Usage: + $PROG + $PROG getlast + $PROG getfinal + $PROG (final|alpha|beta|candidate) [-s (major|minor|patch|auto) | -o] + $PROG --help + $PROG --version +Options: + -s The scope that must be increased, can be major, minor or patch. + The resulting version will match X.Y.Z(-PRERELEASE)(+BUILD) + where X, Y and Z are positive integers, PRERELEASE is an optionnal + string composed of alphanumeric characters describing if the build is + a release candidate, alpha or beta version, with a number. + BUILD is also an optional string composed of alphanumeric + characters and hyphens. + Setting the scope as 'auto', the script will chose the scope between + 'minor' and 'patch', depending on the amount of lines added (<10% will + choose patch). + -v Specifies manually the version to be tagged, must be a valid semantic version + in the format X.Y.Z where X, Y and Z are positive integers. + -o Output the version only, shows the bumped version, but doesn't tag. + -f Forces to tag, even if there are unstaged or uncommited changes. +Commands: + --help Print this help message. + --version Prints the program's version. + get Returns both current final version and last tagged version. + getlast Returns the latest tagged version. + getfinal Returns the latest tagged final version. + getcurrent Returns the current version, based on the latest one, if there are uncommited or + unstaged changes, they will be reflected in the version, adding the number of + pending commits, current branch and commit hash. + final Tags the current build as a final version, this only can be done on the master branch. + candidate Tags the current build as a release candidate, the tag will contain all + the commits from the last final version. + alpha Tags the current build as an alpha version, the tag will contain all + the commits from the last final version. + beta Tags the current build as a beta version, the tag will contain all + the commits from the last final version." + +# Commands and options +ACTION="getlast" +ACTION="$1" +shift + +# We get the parameters +while getopts "v:s:of" opt; do + case $opt in + v) + forcedversion="$OPTARG" + ;; + s) + scope="$OPTARG" + ;; + o) + displayonly="true" + ;; + f) + forcetag="true" + ;; + \?) + echo "Invalid option: -$OPTARG" >&2 + exit 1 + ;; + :) + echo "Option -$OPTARG requires an argument." >&2 + exit 1 + ;; + esac +done + +# Gets a string with the version and returns an array of maximum size of 5 with all the parts of the sematinc version +# $1 The string containing the version in semantic format +# $2 The variable to store the result array: +# position 0: major number +# position 1: minor number +# position 2: patch number +# position 3: identifier (or prerelease identifier) +# position 4: build info +function explode_version { + local __version=$1 + local __result=$2 + if [[ $__version =~ $SEMVER_REGEX ]] ; then + local __major=${BASH_REMATCH[1]} + local __minor=${BASH_REMATCH[2]} + local __patch=${BASH_REMATCH[3]} + local __prere=${BASH_REMATCH[4]} + local __build=${BASH_REMATCH[5]} + eval "$__result=(\"$__major\" \"$__minor\" \"$__patch\" \"$__prere\" \"$__build\")" + else + eval "$__result=" + fi +} + +# Compare two versions and returns -1, 0 or 1 +# $1 The first version to compare +# $2 The second version to compare +# $3 The variable where to store the result +function compare_versions { + local __first + local __second + explode_version $1 __first + explode_version $2 __second + local lv=$3 + + # Compares MAJOR, MINOR and PATCH + for i in 0 1 2; do + local __numberfirst=${__first[$i]} + local __numbersecond=${__second[$i]} + case $(($__numberfirst - $__numbersecond)) in + 0) + ;; + -[0-9]*) + eval "$lv=-1" + return 0 + ;; + [0-9]*) + eval "$lv=1" + return 0 + ;; + esac + done + + # Identifiers should compare with the ASCII order. + local __identifierfirst=${__first[3]} + local __identifiersecond=${__second[3]} + if [[ -n "$__identifierfirst" ]] && [[ -n "$__identifiersecond" ]]; then + if [[ "$__identifierfirst" > "$__identifiersecond" ]]; then + eval "$lv=1" + return 0 + elif [[ "$__identifierfirst" < "$__identifiersecond" ]]; then + eval "$lv=-1" + return 0 + fi + elif [[ -z "$__identifierfirst" ]] && [[ -n "$__identifiersecond" ]]; then + eval "$lv=1" + return 0 + elif [[ -n "$__identifierfirst" ]] && [[ -z "$__identifiersecond" ]]; then + eval "$lv=-1" + return 0 + fi + + eval "$lv=0" +} + +# Returns the last version of two +# $1 The first version to compare +# $2 The second version to compare +# $3 The variable where to store the last one +function get_latest_of_two { + local __first=$1 + local __second=$2 + local __result + local __latest=$3 + compare_versions $__first $__second __result + case $__result in + 0) + eval "$__latest=$__second" + ;; + -1) + eval "$__latest=$__second" + ;; + 1) + eval "$__latest=$__first" + ;; + esac +} + +# Assigns a 2 size array with the identifier, having the identifier at pos 0, and the number in pos 1 +# $1 The identifier in the format -id.# +# $2 The vferiable where to store the 2 size array +function explode_identifier { + local __identifier=$1 + local __result=$2 + if [[ $__identifier =~ $IDENTIFIER_REGEX ]] ; then + local __id=${BASH_REMATCH[1]} + local __number=${BASH_REMATCH[2]} + if [[ -z "$__number" ]]; then + __number=1 + fi + eval "$__result=(\"$__id\" \"$__number\")" + else + eval "$__result=" + fi +} + +# Gets a list of tags and assigns the base and latest versions +# Receives an array with the tags containing the versions +# Assigns to the global variables finalversion and lastversion the final version and the latest version +function get_latest { + local __taglist=("$@") + local __tagsnumber=${#__taglist[@]} + local __current + case $__tagsnumber in + 0) + finalversion=$FIRST_VERSION + lastversion=$FIRST_VERSION + ;; + 1) + __current=${__taglist[0]} + explode_version $__current ver + if [ -n "$ver" ]; then + if [ -n "${ver[3]}" ]; then + finalversion=$FIRST_VERSION + else + finalversion=$__current + fi + lastversion=$__current + else + finalversion=$FIRST_VERSION + lastversion=$FIRST_VERSION + fi + ;; + *) + local __lastpos=$(($__tagsnumber-1)) + for i in $(seq 0 $__lastpos) + do + __current=${__taglist[i]} + explode_version ${__taglist[i]} ver + if [ -n "$ver" ]; then + if [ -z "${ver[3]}" ]; then + get_latest_of_two $finalversion $__current finalversion + get_latest_of_two $lastversion $finalversion lastversion + else + get_latest_of_two $lastversion $__current lastversion + fi + fi + done + ;; + esac + + if git rev-parse -q --verify "refs/tags/$lastversion" >/dev/null; then + hasversiontag="true" + else + hasversiontag="false" + fi +} + +# Gets the next version given the provided scope +# $1 The version that is going to be bumped +# $2 The scope to bump +# $3 The variable where to stoer the result +function get_next_version { + local __exploded + local __fromversion=$1 + local __scope=$2 + local __result=$3 + explode_version $__fromversion __exploded + case $__scope in + major) + __exploded[0]=$((${__exploded[0]}+1)) + __exploded[1]=0 + __exploded[2]=0 + ;; + minor) + __exploded[1]=$((${__exploded[1]}+1)) + __exploded[2]=0 + ;; + patch) + __exploded[2]=$((${__exploded[2]}+1)) + ;; + esac + + eval "$__result=v${__exploded[0]}.${__exploded[1]}.${__exploded[2]}" +} + +function bump_version { + ## First we try to get the next version based on the existing last one + if [ "$scope" == "auto" ]; then + get_scope_auto scope + fi + + local __candidatefromlast=$FIRST_VERSION + local __explodedlast + explode_version $lastversion __explodedlast + if [[ -n "${__explodedlast[3]}" ]]; then + # Last version is not final + local __idlast + explode_identifier ${__explodedlast[3]} __idlast + + # We get the last, given the desired id based on the scope + __candidatefromlast="v${__explodedlast[0]}.${__explodedlast[1]}.${__explodedlast[2]}" + if [[ -n "$identifier" ]]; then + local __nextid="$identifier.1" + if [ "$identifier" == "${__idlast[0]}" ]; then + # We target the same identifier as the last so we increase one + __nextid="$identifier.$(( ${__idlast[1]}+1 ))" + __candidatefromlast="$__candidatefromlast-$__nextid" + else + # Different identifiers, we make sure we are assigning a higher identifier, if not, we increase the version + __candidatefromlast="$__candidatefromlast-$__nextid" + local __comparedwithlast + compare_versions $__candidatefromlast $lastversion __comparedwithlast + if [ "$__comparedwithlast" == -1 ]; then + get_next_version $__candidatefromlast $scope __candidatefromlast + __candidatefromlast="$__candidatefromlast-$__nextid" + fi + fi + fi + fi + + # Then we try to get the version based on the latest final one + local __candidatefromfinal=$FIRST_VERSION + get_next_version $finalversion $scope __candidatefromfinal + if [[ -n "$identifier" ]]; then + __candidatefromfinal="$__candidatefromfinal-$identifier.1" + fi + + # Finally we compare both candidates + local __resultversion + local __result + compare_versions $__candidatefromlast $__candidatefromfinal __result + case $__result in + 0) + __resultversion=$__candidatefromlast + ;; + -1) + __resultversion="$__candidatefromfinal" + ;; + 1) + __resultversion=$__candidatefromlast + ;; + esac + + eval "$1=$__resultversion" +} + +function increase_version { + local __version= + + if [ -z $forcedversion ]; then + bump_version __version + else + if [[ $forcedversion =~ $SEMVER_REGEX ]] ; then + compare_versions $forcedversion $lastversion __result + if [ $__result -le 0 ]; then + echo "Version can't be lower than last version: $lastversion" + exit 1 + fi + else + echo "Non valid version to bump" + exit 1 + fi + __version=$forcedversion + fi + + if [ "$displayonly" == "true" ]; then + echo "$__version" + else + if [ "$forcetag" == "false" ]; then + check_git_dirty_status + fi + local __commitlist + if [ "$finalversion" == "$FIRST_VERSION" ] || [ "$hasversiontag" != "true" ]; then + __commitlist="$(git log --pretty=oneline | cat)" + else + __commitlist="$(git log --pretty=oneline $finalversion... | cat)" + fi + + # If we are forcing a bump, we add bump to the commit list + if [[ -z $__commitlist && "$forcetag" == "true" ]]; then + __commitlist="bump" + fi + + if [[ -z $__commitlist ]]; then + echo "No commits since the last final version, not bumping version" + else + if [[ -z $versionname ]]; then + versionname=$(date -u +"%Y-%m-%dT%H:%M:%SZ") + fi + local __message="$versionname +$__commitlist" + + # We check we have info on the user + local __username=$(git config user.name) + if [ -z "$__username" ]; then + __username=$(id -u -n) + git config user.name $__username + fi + local __useremail=$(git config user.email) + if [ -z "$__useremail" ]; then + __useremail=$(hostname) + git config user.email "$__username@$__useremail" + fi + + git tag -a $__version -m "$__message" + + # If we have a remote, we push there + local __remotes=$(git remote) + if [[ -n $__remotes ]]; then + for __remote in $__remotes; do + git push $__remote $__version > /dev/null + if [ $? -eq 0 ]; then + echo "$__version pushed to $__remote" + else + echo "Error pushing the tag $__version to $__remote" + exit 1 + fi + done + else + echo "$__version" + fi + fi + fi +} + +function check_git_dirty_status { + local __repostatus= + get_work_tree_status __repostatus + + if [ "$__repostatus" == "uncommitted" ]; then + echo "ERROR: You have uncommitted changes" + git status --porcelain + exit 1 + fi + + if [ "$__repostatus" == "unstaged" ]; then + echo "ERROR: You have unstaged changes" + git status --porcelain + exit 1 + fi +} + +# Get the total amount of lines of code in the repo +function get_total_lines { + local __empty_id="$(git hash-object -t tree /dev/null)" + local __changes="$(git diff --numstat $__empty_id | cat)" + local __added_deleted=$1 + get_changed_lines "$__changes" $__added_deleted +} + +# Get the total amount of lines of code since the provided tag +function get_sincetag_lines { + local __sincetag=$1 + local __changes="$(git diff --numstat $__sincetag | cat)" + local __added_deleted=$2 + get_changed_lines "$__changes" $__added_deleted +} + +function get_changed_lines { + local __changes_numstat=$1 + local __result=$2 + IFS=$'\n' read -rd '' -a __changes_array <<<"$__changes_numstat" + local __diff_regex="^([0-9]+)[[:space:]]+([0-9]+)[[:space:]]+.+$" + + local __total_added=0 + local __total_deleted=0 + for i in "${__changes_array[@]}" + do + if [[ $i =~ $__diff_regex ]] ; then + local __added=${BASH_REMATCH[1]} + local __deleted=${BASH_REMATCH[2]} + __total_added=$(( $__total_added+$__added )) + __total_deleted=$(( $__total_deleted+$__deleted )) + fi + done + eval "$2=( $__total_added $__total_deleted )" +} + +function get_scope_auto { + local __verbose=$2 + local __total=0 + local __since=0 + local __scope= + + get_total_lines __total + get_sincetag_lines $finalversion __since + + local __percentage=0 + if [ "$__total" != "0" ]; then + local __percentage=$(( 100*$__since/$__total )) + if [ $__percentage -gt "10" ]; then + __scope="minor" + else + __scope="patch" + fi + fi + + eval "$1=$__scope" + if [[ -n "$__verbose" ]]; then + echo "[Auto Scope] Percentage of lines changed: $__percentage" + echo "[Auto Scope] : $__scope" + fi +} + +function get_work_tree_status { + # Update the index + git update-index -q --ignore-submodules --refresh > /dev/null + eval "$1=" + + if ! git diff-files --quiet --ignore-submodules -- > /dev/null + then + eval "$1=unstaged" + fi + + if ! git diff-index --cached --quiet HEAD --ignore-submodules -- > /dev/null + then + eval "$1=uncommitted" + fi +} + +function get_current { + if [ "$hasversiontag" == "true" ]; then + local __commitcount="$(git rev-list $lastversion.. --count)" + else + local __commitcount="$(git rev-list --count HEAD)" + fi + local __status= + get_work_tree_status __status + + if [ "$__commitcount" == "0" ] && [ -z "$__status" ]; then + eval "$1=$lastversion" + else + local __buildinfo="$(git rev-parse --short HEAD)" + local __currentbranch="$(git rev-parse --abbrev-ref HEAD)" + if [ "$__currentbranch" != "master" ]; then + __buildinfo="$__currentbranch.$__buildinfo" + fi + + local __suffix= + if [ "$__commitcount" != "0" ]; then + if [ -n "$__suffix" ]; then + __suffix="$__suffix." + fi + __suffix="$__suffix$__commitcount" + fi + if [ -n "$__status" ]; then + if [ -n "$__suffix" ]; then + __suffix="$__suffix." + fi + __suffix="$__suffix$__status" + fi + + __suffix="$__suffix+$__buildinfo" + if [ "$lastversion" == "$finalversion" ]; then + scope="patch" + identifier= + local __bumped= + bump_version __bumped + eval "$1=$__bumped-dev.$__suffix" + else + eval "$1=$lastversion.$__suffix" + fi + fi +} + +function init { + git fetch > /dev/null + TAGS="$(git tag)" + IFS=$'\n' read -rd '' -a TAG_ARRAY <<<"$TAGS" + + get_latest ${TAG_ARRAY[@]} + currentbranch="$(git rev-parse --abbrev-ref HEAD)" +} + +case $ACTION in + --help) + echo -e "$HELP" + ;; + --version) + echo -e "${PROG}: $PROG_VERSION" + ;; + final) + init + diff=$(git diff master | cat) + if [ "$forcetag" == "false" ]; then + if [ -n "$diff" ]; then + echo "ERROR: Branch must be updated with master for final versions" + exit 1 + fi + fi + increase_version + ;; + alpha|beta) + init + identifier="$ACTION" + increase_version + ;; + candidate) + init + identifier="rc" + increase_version + ;; + getlast) + init + echo "$lastversion" + ;; + getfinal) + init + echo "$finalversion" + ;; + getcurrent) + init + get_current current + echo "$current" + ;; + get) + init + echo "Current final version: $finalversion" + echo "Last tagged version: $lastversion" + ;; + *) + echo "'$ACTION' is not a valid command, see --help for available commands." + ;; +esac \ No newline at end of file From eb09fcabb112d497b687b065d288a58b79531c92 Mon Sep 17 00:00:00 2001 From: Edward Lynes Date: Fri, 18 Sep 2020 09:51:47 -0400 Subject: [PATCH 04/16] TFP-200: fix zone create sig failure --- configdns-v2/zone.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configdns-v2/zone.go b/configdns-v2/zone.go index 28b84587..d8197e8d 100644 --- a/configdns-v2/zone.go +++ b/configdns-v2/zone.go @@ -432,7 +432,7 @@ func (zone *ZoneCreate) SaveChangelist() error { Config, "POST", "/config-dns/v2/changelists/?zone="+zone.Zone, - nil, + "", ) if err != nil { return err @@ -474,7 +474,7 @@ func (zone *ZoneCreate) SubmitChangelist() error { Config, "POST", "/config-dns/v2/changelists/"+zone.Zone+"/submit", - nil, + "", ) if err != nil { return err From c0d57c62ca55447721fe3155dd2fcd5ae599caa9 Mon Sep 17 00:00:00 2001 From: Edward Lynes Date: Tue, 29 Sep 2020 09:25:04 -0400 Subject: [PATCH 05/16] Pass empty string in Post create body --- configgtm-v1_4/datacenter.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configgtm-v1_4/datacenter.go b/configgtm-v1_4/datacenter.go index c7e39c44..7bd25808 100644 --- a/configgtm-v1_4/datacenter.go +++ b/configgtm-v1_4/datacenter.go @@ -231,7 +231,7 @@ func createDefaultDC(defaultID int, domainName string) (*Datacenter, error) { Config, "POST", defaultURL, - nil, + "", ) if err != nil { return nil, err From 9096ced63c19880ac99a142620cadc09b1f62f08 Mon Sep 17 00:00:00 2001 From: "St. Lawrence, Zachary" Date: Tue, 6 Oct 2020 15:42:03 -0400 Subject: [PATCH 06/16] TFP-228 update readme for v1 release --- README.md | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 1fc9ebbb..e3cbe0c8 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# Akamai OPEN EdgeGrid for GoLang +# Akamai OPEN EdgeGrid for GoLang v1 [![Build Status](https://travis-ci.org/akamai/AkamaiOPEN-edgegrid-golang.svg?branch=master)](https://travis-ci.org/akamai/AkamaiOPEN-edgegrid-golang) [![GoDoc](https://godoc.org/github.com/akamai/AkamaiOPEN-edgegrid-golang?status.svg)](https://godoc.org/github.com/akamai/AkamaiOPEN-edgegrid-golang) @@ -7,9 +7,23 @@ This library implements an Authentication handler for [net/http](https://golang.org/pkg/net/http/) that provides the [Akamai OPEN Edgegrid Authentication](https://developer.akamai.com/introduction/Client_Auth.html) -scheme. For more information visit the [Akamai OPEN Developer Community](https://developer.akamai.com). +scheme. For more information visit the [Akamai OPEN Developer Community](https://developer.akamai.com). This library +has been released as a v1 library though future development will be on the v2 branch -## Usage +## Announcing Akamai OPEN EdgeGrid for GoLang v2 (release v2.0.0) + +The v2 branch of this module is under active development and provides a subset of Akamai APIs for use in the +Akamai Terraform Provider. The v2 branch **does not yet** implement the full set of Akamai endpoints supported by the +0.x and 1.x releases. + +New users are encouraged to adopt v2 branch it is a simpler API wrapper with little to no business logic. + +Current direct users of this v0.9 library are recommended to continue to use the the v1 version as initialization +and class organization has significantly changed in v2 and will require substantial work to migrate existing +applications. Non-backwards compatible changes were made to improve the code quality and make the project more +maintainable. + +## Usage of the v1 library GET Example: From e854dc6aa0ebb28015fcf3a78eb8c7b4bfd9a7c1 Mon Sep 17 00:00:00 2001 From: "St. Lawrence, Zachary" Date: Tue, 6 Oct 2020 16:15:36 -0400 Subject: [PATCH 07/16] Added changelog for previous releases --- CHANGELOG.md | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 CHANGELOG.md diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 00000000..78593661 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,57 @@ +# RELEASE NOTES + +## 2.0.0 (Oct 11, 2020) +* [IMPORTANT] Breaking changes from earlier clients. Project updated to use v2 directory structure. +* [ADD] Project re-organized to prepare for additional APIs to be included in future versions of this library. + +## 1.0.0 (Oct 11, 2020) +* first official release for the edggrid goland library +* DNSv2 - fix zone create signature +* papi - Return nil instead of error if no cp code was found + +## 0.9.18 (Jul 13, 2020) +* [AT-40][Add] Preliminary Logging CorrelationID + +## 0.9.17 (Jun 9, 2020) +* Corrected AKAMAICDN target parsing +* Added endpoints for list zones, creating and updating multiple recordsets +* Refactored recordsets into separate source file + +## 0.9.16 (May 29, 2020) +* Client-v1, Papi-v1 Updates +* Add lock around http request creation. +* papi - add logging to papi endpoints. + +## 0.9.15 (May 15, 2020) +* DNSv2 - Added CERT, TSLA Record parsing. Removed MX Record parsing + +## 0.9.14 (May 12, 2020) +* DNSv2 - Enhance RecordError functions + +## 0.9.13 (Apr 26, 2020) +* DNSv2 - filterZoneCreate check upper case Type + +## 0.9.12 (Apr 21, 2020) +* DNSv2 - Added optional arg to bypass dns record lock for create, update and delete functions. default preserves prior behavior + +## 0.9.11 (Apr 13 , 2020) +* DNSv2 Updates + * Add additional fields, including TSIG, to zone + * Support alias zone types + * Add utility functions for Rdata parsing and process. + * Add GetRecord, GetRecordSet functions + * Add additional Recordset metadata +* Add http request/response logging + +## 0.9.10 (Mar 5, 2020) +* Add support for caching Edgehostnames and Products +* Support for cache in papi library for edgehostnames and products to minimize round trips to fetch repeated common data to avoid + WAF deny rule IPBLOCK-BURST4-54013 issue + +## 0.9.9 (Feb 29, 2020) +* Add support for caching Contract, Groups, and Cp Codes +* cache to minimize round trips on repeated common data fetches to avoid + WAF deny rule IPBLOCK-BURST4-54013 issue + +## 0.9.0 (Aug 6, 2019) +* Added support for GTM From ca72fb88ec9dabc2aaa1d2f4e0796bf896ea677d Mon Sep 17 00:00:00 2001 From: "St. Lawrence, Zachary" Date: Tue, 13 Oct 2020 14:02:44 -0400 Subject: [PATCH 08/16] TFP-228 updated readme with architect feedback --- CHANGELOG.md | 3 ++- README.md | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78593661..08a91be7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,7 +2,8 @@ ## 2.0.0 (Oct 11, 2020) * [IMPORTANT] Breaking changes from earlier clients. Project updated to use v2 directory structure. -* [ADD] Project re-organized to prepare for additional APIs to be included in future versions of this library. +* [ENHANCEMENT] Papi - Api error return to the user when an activation or validation error occurs. +* [NOTE] Project re-organized to prepare for additional APIs to be included in future versions of this library. ## 1.0.0 (Oct 11, 2020) * first official release for the edggrid goland library diff --git a/README.md b/README.md index e3cbe0c8..21b44fd7 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ Akamai Terraform Provider. The v2 branch **does not yet** implement the full set New users are encouraged to adopt v2 branch it is a simpler API wrapper with little to no business logic. Current direct users of this v0.9 library are recommended to continue to use the the v1 version as initialization -and class organization has significantly changed in v2 and will require substantial work to migrate existing +and package structure has significantly changed in v2 and will require substantial work to migrate existing applications. Non-backwards compatible changes were made to improve the code quality and make the project more maintainable. From daf8f46cb360dffe2c0bf4434ad96c1c1825fe23 Mon Sep 17 00:00:00 2001 From: "St. Lawrence, Zachary" Date: Tue, 13 Oct 2020 14:08:31 -0400 Subject: [PATCH 09/16] Updated with additional feedback --- CHANGELOG.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 08a91be7..d5c41cf1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,12 +1,12 @@ -# RELEASE NOTES +# EDGEGRID GOLANG RELEASE NOTES -## 2.0.0 (Oct 11, 2020) +## 2.0.0 (Oct 15, 2020) * [IMPORTANT] Breaking changes from earlier clients. Project updated to use v2 directory structure. * [ENHANCEMENT] Papi - Api error return to the user when an activation or validation error occurs. * [NOTE] Project re-organized to prepare for additional APIs to be included in future versions of this library. -## 1.0.0 (Oct 11, 2020) -* first official release for the edggrid goland library +## 1.0.0 (Oct 15, 2020) +* first official release for the EdgeGrid Golang library * DNSv2 - fix zone create signature * papi - Return nil instead of error if no cp code was found From bbabd3c0a878720c0c8b8e77018b52f7d05c9aaa Mon Sep 17 00:00:00 2001 From: "St. Lawrence, Zachary" Date: Wed, 14 Oct 2020 15:52:50 -0400 Subject: [PATCH 10/16] Updated go version and changelog to cover two fixes in this release --- CHANGELOG.md | 9 +++++---- go.mod | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d5c41cf1..d20594d0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,13 +2,14 @@ ## 2.0.0 (Oct 15, 2020) * [IMPORTANT] Breaking changes from earlier clients. Project updated to use v2 directory structure. -* [ENHANCEMENT] Papi - Api error return to the user when an activation or validation error occurs. +* [ENHANCEMENT] PAPI - Api error return to the user when an activation or validation error occurs. * [NOTE] Project re-organized to prepare for additional APIs to be included in future versions of this library. ## 1.0.0 (Oct 15, 2020) -* first official release for the EdgeGrid Golang library -* DNSv2 - fix zone create signature -* papi - Return nil instead of error if no cp code was found +* Official release for the EdgeGrid Golang library +* DNSv2 - Zone create signature to pass blank instead of nil +* PAPI - Return nil instead of error if no cp code was found +* GTM - Datacenter API requires blank instead of nil ## 0.9.18 (Jul 13, 2020) * [AT-40][Add] Preliminary Logging CorrelationID diff --git a/go.mod b/go.mod index 0c04fd42..1d54742d 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/akamai/AkamaiOPEN-edgegrid-golang -go 1.12 +go 1.14 require ( github.com/google/go-querystring v1.0.0 From 802b7d0ad709c613717d080719471274c8c94e35 Mon Sep 17 00:00:00 2001 From: "St. Lawrence, Zachary" Date: Thu, 15 Oct 2020 13:30:57 -0400 Subject: [PATCH 11/16] removed pom.xml --- pom.xml | 114 -------------------------------------------------------- 1 file changed, 114 deletions(-) delete mode 100644 pom.xml diff --git a/pom.xml b/pom.xml deleted file mode 100644 index 768a075e..00000000 --- a/pom.xml +++ /dev/null @@ -1,114 +0,0 @@ - - 4.0.0 - com.akamai.fee - akamaiopen-edgegrid-golang - mvn-golang - 1.0-SNAPSHOT - akamai edgegrid golang - - - - com.akamai - luna - 1.7 - - - - - none - - - UTF-8 - true - true - - - 1.4 - 2.3.4 - 3.0.0 - 1.0.0 - - - - - - primary-akamai-nexus - https://lunabuild.akamai.com/nexus/content/groups/public/ - - true - daily - - - - - - - ${basedir}${file.separator} - ${basedir}${file.separator}dist - akamaiopen-edgegrid-golang - - - com.igormaznitsa - mvn-golang-wrapper - ${mvn-golang-wrapper-plugin.version} - true - - - - install - - - true - - - - - github.com/akamai/AkamaiOPEN-edgegrid-golang - - - - - - - - - org.codehaus.mojo - buildnumber-maven-plugin - ${buildnumber-maven-plugin.version} - - - validate - - create - - - - - lastgitcommit - false - false - unknown - - - - - org.codehaus.mojo - properties-maven-plugin - ${properties-maven-plugin.version} - - dist/build.properties - - - - generate-resources - - write-project-properties - - - - - - - - From b2131707c2c98ba6d60cafb47939bcc5f38c246a Mon Sep 17 00:00:00 2001 From: Edward Lynes Date: Thu, 15 Oct 2020 16:01:27 -0400 Subject: [PATCH 12/16] Added PostMasterZoneFile func --- configdns-v2/zone.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/configdns-v2/zone.go b/configdns-v2/zone.go index d8197e8d..52defb59 100644 --- a/configdns-v2/zone.go +++ b/configdns-v2/zone.go @@ -360,6 +360,45 @@ func GetMasterZoneFile(zone string) (string, error) { } } +// Update Master Zone file +func PostMasterZoneFile(zone string, filedata *string) error { + + req, err := client.NewJSONRequest( + Config, + "POST", + fmt.Sprintf("/config-dns/v2/zones/%s/zone-file", zone), + filedata, + ) + if err != nil { + return err + } + + req.Header.Add("Accept", "text/dns") + + edge.PrintHttpRequest(req, true) + + res, err := client.Do(Config, req) + + // Network error + if err != nil { + return &ZoneError{ + zoneName: zone, + httpErrorMessage: err.Error(), + err: err, + } + } + + edge.PrintHttpResponse(res, true) + + // API error + if client.IsError(res) { + err := client.NewAPIError(res) + return &ZoneError{zoneName: zone, apiErrorMessage: err.Detail, err: err} + } + + return nil +} + // Create a Zone func (zone *ZoneCreate) Save(zonequerystring ZoneQueryString, clearConn ...bool) error { // This lock will restrict the concurrency of API calls From 9ab7a903728bc9c65aa4b5028a0f1e8ebccacd3d Mon Sep 17 00:00:00 2001 From: Edward Lynes Date: Fri, 16 Oct 2020 10:45:08 -0400 Subject: [PATCH 13/16] add --- configdns-v2/zonebulk.go | 229 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 229 insertions(+) create mode 100644 configdns-v2/zonebulk.go diff --git a/configdns-v2/zonebulk.go b/configdns-v2/zonebulk.go new file mode 100644 index 00000000..2e60473b --- /dev/null +++ b/configdns-v2/zonebulk.go @@ -0,0 +1,229 @@ +package dnsv2 + +import ( + "fmt" + "github.com/akamai/AkamaiOPEN-edgegrid-golang/client-v1" + edge "github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid" +) + +/* +type ZoneQueryString struct { + Contract string + Group string +} + +type ZoneCreate struct { + Zone string `json:"zone"` + Type string `json:"type"` + Masters []string `json:"masters,omitempty"` + Comment string `json:"comment,omitempty"` + SignAndServe bool `json:"signAndServe"` + SignAndServeAlgorithm string `json:"signAndServeAlgorithm,omitempty"` + TsigKey *TSIGKey `json:"tsigKey,omitempty"` + Target string `json:"target,omitempty"` + EndCustomerId string `json:"endCustomerId,omitempty"` + ContractId string `json:"contractId,omitempty"` +} +*/ + +type BulkZonesCreate struct { + Zones []*ZoneCreate `json:"zones"` +} + +type BulkZonesResponse struct { + RequestId string `json:"requestId"` + ExpirationDate string `json:"expirationDate"` +} + +type BulkStatusResponse struct { + RequestId string `json:"requestId"` + ZonesSubmitted int `json:"zonesSubmitted"` + SuccessCount int `json:"successCount"` + FailureCount int `json:"failureCount"` + IsComplete bool `json:"isComplete"` + ExpirationDate string `json:"expirationDate"` +} + +// Get Bulk Zone Create Status +func GetBulkZoneCreateStatus(requestid string) (*BulkStatusResponse, error) { + + bulkzonesurl := fmt.Sprintf("/config-dns/v2/zones/create-requests/%s", requestid) + req, err := client.NewRequest( + Config, + "GET", + bulkzonesurl, + nil, + ) + if err != nil { + return nil, err + } + + edge.PrintHttpRequest(req, true) + + res, err := client.Do(Config, req) + + // Network error + if err != nil { + return nil, &ZoneError{ + zoneName: "bulk zone create status", + httpErrorMessage: err.Error(), + err: err, + } + } + + edge.PrintHttpResponse(res, true) + + // API error + if client.IsError(res) { + err := client.NewAPIError(res) + return nil, &ZoneError{zoneName: "bulk zone create status", apiErrorMessage: err.Detail, err: err} + } + + bulkresponse := &BulkStatusResponse{} + err = client.BodyJSON(res, bulkresponse) + if err != nil { + return nil, err + } + + return bulkresponse, nil +} + +// Get Bulk Zone Delete Status +func GetBulkZoneDeleteStatus(requestid string) (*BulkStatusResponse, error) { + + bulkzonesurl := fmt.Sprintf("/config-dns/v2/zones/delete-requests/%s", requestid) + req, err := client.NewRequest( + Config, + "GET", + bulkzonesurl, + nil, + ) + if err != nil { + return nil, err + } + + edge.PrintHttpRequest(req, true) + + res, err := client.Do(Config, req) + + // Network error + if err != nil { + return nil, &ZoneError{ + zoneName: "bulk zone delete status", + httpErrorMessage: err.Error(), + err: err, + } + } + + edge.PrintHttpResponse(res, true) + + // API error + if client.IsError(res) { + err := client.NewAPIError(res) + return nil, &ZoneError{zoneName: "bulk zone delete status", apiErrorMessage: err.Detail, err: err} + } + + bulkresponse := &BulkStatusResponse{} + err = client.BodyJSON(res, bulkresponse) + if err != nil { + return nil, err + } + + return bulkresponse, nil +} + +// Bulk Create Zones +func CreateBulkZones(bulkzones *BulkZonesCreate, zonequerystring ZoneQueryString) (*BulkZonesResponse, error) { + + bulkzonesurl := "/config-dns/v2/zones/create-requests?contractId=" + zonequerystring.Contract + if len(zonequerystring.Group) > 0 { + bulkzonesurl += "&gid=" + zonequerystring.Group + } + req, err := client.NewJSONRequest( + Config, + "POST", + bulkzonesurl, + bulkzones, + ) + if err != nil { + return nil, err + } + + edge.PrintHttpRequest(req, true) + + res, err := client.Do(Config, req) + + // Network error + if err != nil { + return nil, &ZoneError{ + zoneName: "bulk zone create", + httpErrorMessage: err.Error(), + err: err, + } + } + + edge.PrintHttpResponse(res, true) + + // API error + if client.IsError(res) { + err := client.NewAPIError(res) + return nil, &ZoneError{zoneName: "bulk zone create", apiErrorMessage: err.Detail, err: err} + } + + bulkresponse := &BulkZonesResponse{} + err = client.BodyJSON(res, bulkresponse) + if err != nil { + return nil, err + } + + return bulkresponse, nil +} + +// Bulk Delete Zones +func DeleteBulkZones(zoneslist *ZoneNameListResponse, bypassSafetyChecks ... bool) (*BulkZonesResponse, error) { + + bulkzonesurl := "/config-dns/v2/zones/delete-requests" + if len(bypassSafetyChecks) > 0 { + bulkzonesurl += fmt.Sprintf("?bypassSafetyChecks=%t", bypassSafetyChecks[0]) + } + + req, err := client.NewJSONRequest( + Config, + "POST", + bulkzonesurl, + zoneslist, + ) + if err != nil { + return nil, err + } + + edge.PrintHttpRequest(req, true) + + res, err := client.Do(Config, req) + + // Network error + if err != nil { + return nil, &ZoneError{ + zoneName: "bulk zone delete", + httpErrorMessage: err.Error(), + err: err, + } + } + + edge.PrintHttpResponse(res, true) + + // API error + if client.IsError(res) { + err := client.NewAPIError(res) + return nil, &ZoneError{zoneName: "bulk zone delete", apiErrorMessage: err.Detail, err: err} + } + + bulkresponse := &BulkZonesResponse{} + err = client.BodyJSON(res, bulkresponse) + if err != nil { + return nil, err + } + + return bulkresponse, nil +} + From d95e2ad80f78e73584e81d0e604236741e9872a8 Mon Sep 17 00:00:00 2001 From: Edward Lynes Date: Fri, 16 Oct 2020 17:16:47 -0400 Subject: [PATCH 14/16] Added Get Result --- configdns-v2/zonebulk.go | 382 +++++++++++++++++++++++++-------------- 1 file changed, 243 insertions(+), 139 deletions(-) diff --git a/configdns-v2/zonebulk.go b/configdns-v2/zonebulk.go index 2e60473b..d9f09952 100644 --- a/configdns-v2/zonebulk.go +++ b/configdns-v2/zonebulk.go @@ -27,109 +27,214 @@ type ZoneCreate struct { */ type BulkZonesCreate struct { - Zones []*ZoneCreate `json:"zones"` + Zones []*ZoneCreate `json:"zones"` } type BulkZonesResponse struct { - RequestId string `json:"requestId"` - ExpirationDate string `json:"expirationDate"` + RequestId string `json:"requestId"` + ExpirationDate string `json:"expirationDate"` } type BulkStatusResponse struct { - RequestId string `json:"requestId"` - ZonesSubmitted int `json:"zonesSubmitted"` - SuccessCount int `json:"successCount"` - FailureCount int `json:"failureCount"` - IsComplete bool `json:"isComplete"` - ExpirationDate string `json:"expirationDate"` + RequestId string `json:"requestId"` + ZonesSubmitted int `json:"zonesSubmitted"` + SuccessCount int `json:"successCount"` + FailureCount int `json:"failureCount"` + IsComplete bool `json:"isComplete"` + ExpirationDate string `json:"expirationDate"` } -// Get Bulk Zone Create Status +type BulkFailedZone struct { + Zone string `json:"zone"` + FailureReason string `json:"failureReason"` +} + +type BulkCreateResultResponse struct { + RequestId string `json:"requestId"` + SuccessfullyCreatedZones []string `json:"successfullyCreatedZones"` + FailedZones []*BulkFailedZone `JSON:"failedZones"` +} + +type BulkDeleteResultResponse struct { + RequestId string `json:"requestId"` + SuccessfullyDeletedZones []string `json:"successfullyDeletedZones"` + FailedZones []*BulkFailedZone `JSON:"failedZones"` +} + +// Get Bulk Zone Create Status func GetBulkZoneCreateStatus(requestid string) (*BulkStatusResponse, error) { - bulkzonesurl := fmt.Sprintf("/config-dns/v2/zones/create-requests/%s", requestid) - req, err := client.NewRequest( - Config, - "GET", - bulkzonesurl, - nil, - ) - if err != nil { - return nil, err - } - - edge.PrintHttpRequest(req, true) - - res, err := client.Do(Config, req) - - // Network error - if err != nil { - return nil, &ZoneError{ - zoneName: "bulk zone create status", - httpErrorMessage: err.Error(), - err: err, - } - } - - edge.PrintHttpResponse(res, true) - - // API error - if client.IsError(res) { - err := client.NewAPIError(res) - return nil, &ZoneError{zoneName: "bulk zone create status", apiErrorMessage: err.Detail, err: err} - } - - bulkresponse := &BulkStatusResponse{} - err = client.BodyJSON(res, bulkresponse) - if err != nil { - return nil, err - } - - return bulkresponse, nil + bulkzonesurl := fmt.Sprintf("/config-dns/v2/zones/create-requests/%s", requestid) + req, err := client.NewRequest( + Config, + "GET", + bulkzonesurl, + nil, + ) + if err != nil { + return nil, err + } + + edge.PrintHttpRequest(req, true) + + res, err := client.Do(Config, req) + + // Network error + if err != nil { + return nil, &ZoneError{ + zoneName: "bulk zone create status", + httpErrorMessage: err.Error(), + err: err, + } + } + + edge.PrintHttpResponse(res, true) + + // API error + if client.IsError(res) { + err := client.NewAPIError(res) + return nil, &ZoneError{zoneName: "bulk zone create status", apiErrorMessage: err.Detail, err: err} + } + + bulkresponse := &BulkStatusResponse{} + err = client.BodyJSON(res, bulkresponse) + if err != nil { + return nil, err + } + + return bulkresponse, nil } // Get Bulk Zone Delete Status func GetBulkZoneDeleteStatus(requestid string) (*BulkStatusResponse, error) { - bulkzonesurl := fmt.Sprintf("/config-dns/v2/zones/delete-requests/%s", requestid) - req, err := client.NewRequest( - Config, - "GET", - bulkzonesurl, - nil, - ) - if err != nil { - return nil, err - } - - edge.PrintHttpRequest(req, true) - - res, err := client.Do(Config, req) - - // Network error - if err != nil { - return nil, &ZoneError{ - zoneName: "bulk zone delete status", - httpErrorMessage: err.Error(), - err: err, - } - } - - edge.PrintHttpResponse(res, true) - - // API error - if client.IsError(res) { - err := client.NewAPIError(res) - return nil, &ZoneError{zoneName: "bulk zone delete status", apiErrorMessage: err.Detail, err: err} - } - - bulkresponse := &BulkStatusResponse{} - err = client.BodyJSON(res, bulkresponse) - if err != nil { - return nil, err - } - - return bulkresponse, nil + bulkzonesurl := fmt.Sprintf("/config-dns/v2/zones/delete-requests/%s", requestid) + req, err := client.NewRequest( + Config, + "GET", + bulkzonesurl, + nil, + ) + if err != nil { + return nil, err + } + + edge.PrintHttpRequest(req, true) + + res, err := client.Do(Config, req) + + // Network error + if err != nil { + return nil, &ZoneError{ + zoneName: "bulk zone delete status", + httpErrorMessage: err.Error(), + err: err, + } + } + + edge.PrintHttpResponse(res, true) + + // API error + if client.IsError(res) { + err := client.NewAPIError(res) + return nil, &ZoneError{zoneName: "bulk zone delete status", apiErrorMessage: err.Detail, err: err} + } + + bulkresponse := &BulkStatusResponse{} + err = client.BodyJSON(res, bulkresponse) + if err != nil { + return nil, err + } + + return bulkresponse, nil +} + +// Get Bulk Zone Create Result +func GetBulkZoneCreateResult(requestid string) (*BulkCreateResultResponse, error) { + + bulkzonesurl := fmt.Sprintf("/config-dns/v2/zones/create-requests/%s/result", requestid) + req, err := client.NewRequest( + Config, + "GET", + bulkzonesurl, + nil, + ) + if err != nil { + return nil, err + } + + edge.PrintHttpRequest(req, true) + + res, err := client.Do(Config, req) + + // Network error + if err != nil { + return nil, &ZoneError{ + zoneName: "bulk zone create result", + httpErrorMessage: err.Error(), + err: err, + } + } + + edge.PrintHttpResponse(res, true) + + // API error + if client.IsError(res) { + err := client.NewAPIError(res) + return nil, &ZoneError{zoneName: "bulk zone create result", apiErrorMessage: err.Detail, err: err} + } + + bulkresponse := &BulkCreateResultResponse{} + err = client.BodyJSON(res, bulkresponse) + if err != nil { + return nil, err + } + + return bulkresponse, nil +} + +// Get Bulk Zone Delete Result +func GetBulkZoneDeleteResult(requestid string) (*BulkDeleteResultResponse, error) { + + bulkzonesurl := fmt.Sprintf("/config-dns/v2/zones/delete-requests/%s/result", requestid) + req, err := client.NewRequest( + Config, + "GET", + bulkzonesurl, + nil, + ) + if err != nil { + return nil, err + } + + edge.PrintHttpRequest(req, true) + + res, err := client.Do(Config, req) + + // Network error + if err != nil { + return nil, &ZoneError{ + zoneName: "bulk zone delete result", + httpErrorMessage: err.Error(), + err: err, + } + } + + edge.PrintHttpResponse(res, true) + + // API error + if client.IsError(res) { + err := client.NewAPIError(res) + return nil, &ZoneError{zoneName: "bulk zone delete result", apiErrorMessage: err.Detail, err: err} + } + + bulkresponse := &BulkDeleteResultResponse{} + err = client.BodyJSON(res, bulkresponse) + if err != nil { + return nil, err + } + + return bulkresponse, nil } // Bulk Create Zones @@ -171,59 +276,58 @@ func CreateBulkZones(bulkzones *BulkZonesCreate, zonequerystring ZoneQueryString } bulkresponse := &BulkZonesResponse{} - err = client.BodyJSON(res, bulkresponse) - if err != nil { - return nil, err - } + err = client.BodyJSON(res, bulkresponse) + if err != nil { + return nil, err + } - return bulkresponse, nil + return bulkresponse, nil } // Bulk Delete Zones -func DeleteBulkZones(zoneslist *ZoneNameListResponse, bypassSafetyChecks ... bool) (*BulkZonesResponse, error) { - - bulkzonesurl := "/config-dns/v2/zones/delete-requests" - if len(bypassSafetyChecks) > 0 { - bulkzonesurl += fmt.Sprintf("?bypassSafetyChecks=%t", bypassSafetyChecks[0]) - } - - req, err := client.NewJSONRequest( - Config, - "POST", - bulkzonesurl, - zoneslist, - ) - if err != nil { - return nil, err - } - - edge.PrintHttpRequest(req, true) - - res, err := client.Do(Config, req) - - // Network error - if err != nil { - return nil, &ZoneError{ - zoneName: "bulk zone delete", - httpErrorMessage: err.Error(), - err: err, - } - } - - edge.PrintHttpResponse(res, true) - - // API error - if client.IsError(res) { - err := client.NewAPIError(res) - return nil, &ZoneError{zoneName: "bulk zone delete", apiErrorMessage: err.Detail, err: err} - } - - bulkresponse := &BulkZonesResponse{} - err = client.BodyJSON(res, bulkresponse) - if err != nil { - return nil, err - } - - return bulkresponse, nil -} +func DeleteBulkZones(zoneslist *ZoneNameListResponse, bypassSafetyChecks ...bool) (*BulkZonesResponse, error) { + + bulkzonesurl := "/config-dns/v2/zones/delete-requests" + if len(bypassSafetyChecks) > 0 { + bulkzonesurl += fmt.Sprintf("?bypassSafetyChecks=%t", bypassSafetyChecks[0]) + } + + req, err := client.NewJSONRequest( + Config, + "POST", + bulkzonesurl, + zoneslist, + ) + if err != nil { + return nil, err + } + + edge.PrintHttpRequest(req, true) + + res, err := client.Do(Config, req) + // Network error + if err != nil { + return nil, &ZoneError{ + zoneName: "bulk zone delete", + httpErrorMessage: err.Error(), + err: err, + } + } + + edge.PrintHttpResponse(res, true) + + // API error + if client.IsError(res) { + err := client.NewAPIError(res) + return nil, &ZoneError{zoneName: "bulk zone delete", apiErrorMessage: err.Detail, err: err} + } + + bulkresponse := &BulkZonesResponse{} + err = client.BodyJSON(res, bulkresponse) + if err != nil { + return nil, err + } + + return bulkresponse, nil +} From 05f974e2965792b1eb1d4e8871ed0b27e8a826e4 Mon Sep 17 00:00:00 2001 From: Ed Lynes Date: Mon, 19 Oct 2020 10:59:28 -0400 Subject: [PATCH 15/16] Refactor PostMasterZoneFile --- configdns-v2/zone.go | 74 +++++++++++++++++++++++--------------------- 1 file changed, 38 insertions(+), 36 deletions(-) diff --git a/configdns-v2/zone.go b/configdns-v2/zone.go index 52defb59..487ff415 100644 --- a/configdns-v2/zone.go +++ b/configdns-v2/zone.go @@ -1,6 +1,7 @@ package dnsv2 import ( + "bytes" "fmt" "github.com/akamai/AkamaiOPEN-edgegrid-golang/client-v1" edge "github.com/akamai/AkamaiOPEN-edgegrid-golang/edgegrid" @@ -361,42 +362,43 @@ func GetMasterZoneFile(zone string) (string, error) { } // Update Master Zone file -func PostMasterZoneFile(zone string, filedata *string) error { - - req, err := client.NewJSONRequest( - Config, - "POST", - fmt.Sprintf("/config-dns/v2/zones/%s/zone-file", zone), - filedata, - ) - if err != nil { - return err - } - - req.Header.Add("Accept", "text/dns") - - edge.PrintHttpRequest(req, true) - - res, err := client.Do(Config, req) - - // Network error - if err != nil { - return &ZoneError{ - zoneName: zone, - httpErrorMessage: err.Error(), - err: err, - } - } - - edge.PrintHttpResponse(res, true) - - // API error - if client.IsError(res) { - err := client.NewAPIError(res) - return &ZoneError{zoneName: zone, apiErrorMessage: err.Detail, err: err} - } - - return nil +func PostMasterZoneFile(zone string, filedata string) error { + + buf := bytes.NewReader([]byte(filedata)) + req, err := client.NewRequest( + Config, + "POST", + fmt.Sprintf("/config-dns/v2/zones/%s/zone-file", zone), + buf, + ) + if err != nil { + return err + } + + req.Header.Set("Content-Type", "text/dns") + + edge.PrintHttpRequest(req, true) + + res, err := client.Do(Config, req) + + // Network error + if err != nil { + return &ZoneError{ + zoneName: zone, + httpErrorMessage: err.Error(), + err: err, + } + } + + edge.PrintHttpResponse(res, true) + + // API error + if client.IsError(res) { + err := client.NewAPIError(res) + return &ZoneError{zoneName: zone, apiErrorMessage: err.Detail, err: err} + } + + return nil } // Create a Zone From 9b4c18f553171c00ff09c364a49a7b87ac02883c Mon Sep 17 00:00:00 2001 From: "St. Lawrence, Zachary" Date: Tue, 20 Oct 2020 15:26:54 -0400 Subject: [PATCH 16/16] string casting of int causing errors on cast --- configgtm-v1_3/datacenter.go | 4 ++-- configgtm-v1_4/datacenter.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/configgtm-v1_3/datacenter.go b/configgtm-v1_3/datacenter.go index 2993d245..ac0bc97f 100644 --- a/configgtm-v1_3/datacenter.go +++ b/configgtm-v1_3/datacenter.go @@ -210,7 +210,7 @@ func (dc *Datacenter) Update(domainName string) (*ResponseStatus, error) { // API error if client.IsError(res) { err := client.NewAPIError(res) - return nil, CommonError{entityName: "Datacenter", name: string(dc.DatacenterId), apiErrorMessage: err.Detail, err: err} + return nil, CommonError{entityName: "Datacenter", name: strconv.Itoa(dc.DatacenterId), apiErrorMessage: err.Detail, err: err} } responseBody := NewDatacenterResponse() @@ -260,7 +260,7 @@ func (dc *Datacenter) Delete(domainName string) (*ResponseStatus, error) { // API error if client.IsError(res) { err := client.NewAPIError(res) - return nil, CommonError{entityName: "Datacenter", name: string(dc.DatacenterId), apiErrorMessage: err.Detail, err: err} + return nil, CommonError{entityName: "Datacenter", name: strconv.Itoa(dc.DatacenterId), apiErrorMessage: err.Detail, err: err} } responseBody := NewDatacenterResponse() diff --git a/configgtm-v1_4/datacenter.go b/configgtm-v1_4/datacenter.go index 7bd25808..61cb4e17 100644 --- a/configgtm-v1_4/datacenter.go +++ b/configgtm-v1_4/datacenter.go @@ -299,7 +299,7 @@ func (dc *Datacenter) Update(domainName string) (*ResponseStatus, error) { // API error if client.IsError(res) { err := client.NewAPIError(res) - return nil, CommonError{entityName: "Datacenter", name: string(dc.DatacenterId), apiErrorMessage: err.Detail, err: err} + return nil, CommonError{entityName: "Datacenter", name: strconv.Itoa(dc.DatacenterId), apiErrorMessage: err.Detail, err: err} } responseBody := NewDatacenterResponse() @@ -349,7 +349,7 @@ func (dc *Datacenter) Delete(domainName string) (*ResponseStatus, error) { // API error if client.IsError(res) { err := client.NewAPIError(res) - return nil, CommonError{entityName: "Datacenter", name: string(dc.DatacenterId), apiErrorMessage: err.Detail, err: err} + return nil, CommonError{entityName: "Datacenter", name: strconv.Itoa(dc.DatacenterId), apiErrorMessage: err.Detail, err: err} } responseBody := NewDatacenterResponse()