aboutsummaryrefslogtreecommitdiffstats
path: root/screwdriver/factory-command.sh
blob: 3b739b9f5c9a2abd894859e853cc742aeaa19acd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#!/bin/bash
# Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
set -eo pipefail

if (( $# < 1 )); then
    echo "Usage: $0 <command> [options]"
    exit 1
fi

COMMAND=$1
FACTORY_API="https://factory.vespa.aws-us-east-1a.vespa.oath.cloud/api/factory/v1"
COOKIEJAR=$(pwd)/jar.txt
trap "rm -f $COOKIEJAR" EXIT

SESSION_TOKEN=$(curl -s -H 'Content-Type: application/json' -H 'Accept: application/json' -d "{ \"username\": \"svc-okta-vespa-factory\", \"password\": \"$SVC_OKTA_VESPA_FACTORY_TOKEN\" }" https://ouryahoo.okta.com/api/v1/authn | jq -re '.sessionToken')
LOCATION=$(curl -s -i -c $COOKIEJAR "https://factory.vespa.aws-us-east-1a.vespa.oath.cloud/login" | grep location | awk '{print $2}' | tr -d '\r')
curl -sL -b $COOKIEJAR -c $COOKIEJAR "$LOCATION&sessionToken=$SESSION_TOKEN" &> /dev/null

CURL="curl -sL -b $COOKIEJAR"

shift
case $COMMAND in
  get-version)
    VERSION=$1
    if [[ -z $VERSION ]]; then echo "Usage: $0 $COMMAND <version>"; exit 1; fi
    $CURL "$FACTORY_API/versions/$VERSION"
    ;;
  create-build)
    $CURL -d "{
        \"startSeconds\": $(date +%s),
        \"sdApiUrl\": \"https://api.screwdriver.cd/v4/\",
        \"pipelineId\": $SD_PIPELINE_ID,
        \"jobId\": $SD_JOB_ID,
        \"buildId\": $SD_BUILD_ID,
        \"platform\": \"opensource_centos7\"
    }" \
    "$FACTORY_API/builds"
    ;;
  create-release)
    $CURL -d "{
        \"startSeconds\": $(date +%s),
        \"systemName\": \"opensource\"
    }" \
    "$FACTORY_API/releases"
    ;;
  update-build-status)
    STATUS=$1
    DESCRIPTION=$2
    if [[ -z $STATUS ]] || [[ -z $DESCRIPTION ]]; then echo "Usage: $0 $COMMAND <status> <description>"; exit 1; fi
    $CURL -d "{
        \"updatedSeconds\": $(date +%s),
        \"sdApiUrl\": \"https://api.screwdriver.cd/v4/\",
        \"pipelineId\": $SD_PIPELINE_ID,
        \"jobId\": $SD_JOB_ID,
        \"buildId\": $SD_BUILD_ID,
        \"status\": \"$STATUS\",
        \"description\": \"$DESCRIPTION\"
    }" \
    "$FACTORY_API/builds/$SD_BUILD_ID/status"
    ;;
  update-released-time)
    VERSION=$1
    if [[ -z $VERSION ]]; then echo "Usage: $0 $COMMAND <version>"; exit 1; fi
    $CURL -d "{
        \"releasedSeconds\": $(date +%s),
        \"systemName\": \"opensource\"
    }" \
    "$FACTORY_API/releases/$VERSION"
    ;;
  *)
    echo "Unknown command $COMMAND"
    exit 1
    ;;
esac