Skip to content

Commit 7d8ec8f

Browse files
authored
Merge pull request #25 from watson-developer-cloud/feature-asoc
Application Security On Cloud
2 parents 09ec94f + 6b45c54 commit 7d8ec8f

File tree

7 files changed

+165
-1
lines changed

7 files changed

+165
-1
lines changed

.travis.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
language: ruby
22
cache: bundler
3+
dist: trusty
34
sudo: required
45

56
rvm:
@@ -18,9 +19,12 @@ install:
1819
- npm install -g semantic-release
1920
- npm install -g @semantic-release/exec
2021
- bundle install
21-
22+
- 'if [ "${TRAVIS_TAG}" = "${TRAVIS_BRANCH}" ]; then cd appscan; make asoc-tool; cd ../; fi'
23+
before_script:
24+
- 'if [ "${TRAVIS_TAG}" = "${TRAVIS_BRANCH}" ]; then chmod a+x ./appscan/ASOC.sh; fi'
2225
script:
2326
- bundle exec rake
27+
- 'if [ "${TRAVIS_TAG}" = "${TRAVIS_BRANCH}" ]; then ./appscan/ASOC.sh; fi'
2428

2529
before_deploy:
2630
- bundle exec rake test:appveyor_status

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
[![codecov.io](https://codecov.io/github/watson-developer-cloud/ruby-sdk/coverage.svg)](https://codecov.io/github/watson-developer-cloud/ruby-sdk)
77
[![Gem Version](https://badge.fury.io/rb/ibm_watson.svg)](https://badge.fury.io/rb/ibm_watson)
88
[![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release)
9+
[![CLA assistant](https://cla-assistant.io/readme/badge/watson-developer-cloud/ruby-sdk)](https://cla-assistant.io/watson-developer-cloud/ruby-sdk)
910

1011
Ruby gem to quickly get started with the various [IBM Watson][wdc] services.
1112

appscan/ASOC.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#!/bin/bash
2+
3+
cd appscan
4+
make generate-irx
5+
make upload-file
6+
make run-scan
7+
cd ../

appscan/Configfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# URLs to the CISO APIs
2+
LOGIN_URL ?= 'https://appscan.ibmcloud.com/api/V2/Account/ApiKeyLogin'
3+
UPLOAD_URL ?= 'https://appscan.ibmcloud.com/api/v2/FileUpload'
4+
GET_APP_URL ?= 'https://appscan.ibmcloud.com/api/V2/Apps?$$$$filter=Name%20eq%20'
5+
STATIC_SCAN_URL ?= 'https://appscan.ibmcloud.com/api/v2/Scans/StaticAnalyzer'
6+
CREATE_APP_URL ?= 'https://appscan.ibmcloud.com/api/V2/Apps'
7+
GET_ASSET_GROUP_URL ?= 'https://appscan.ibmcloud.com/api/V2/AssetGroups'
8+
9+
APPSCAN_CLIENT_URL ?= https://appscan.ibmcloud.com/api/SCX/StaticAnalyzer/SAClientUtil?os=
10+
OS ?= linux
11+
APPSCAN_TOOL := $(APPSCAN_CLIENT_URL)$(OS)
12+
13+
GIT_REPO ?= [email protected]:watson-developer-cloud/ruby-sdk.git
14+
15+
PROJECT_NAME ?= ruby-sdk
16+
17+
# Headers added to curl command
18+
CONTENT_HEADER_JSON := --header 'Content-Type: application/json'
19+
ACCEPT_HEADER_JSON := --header 'Accept: application/json'

appscan/Makefile

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
include Configfile
2+
3+
# This will configure a 32-bit architecture on top of a 64-bit linux machine
4+
config-arch:
5+
sudo dpkg --add-architecture i386
6+
sudo apt-get update
7+
sudo apt-get install libc6:i386 libncurses5:i386 libstdc++6:i386
8+
9+
# Gets the ASoC Client Tool and configures it
10+
asoc-tool: config-arch
11+
$(eval DIR := $(shell pwd))
12+
curl -o $(HOME)/client.zip $(APPSCAN_TOOL)
13+
mkdir $(HOME)/client ; mkdir $(HOME)/tool
14+
unzip -qq $(HOME)/client.zip -d $(HOME)/client
15+
cd $(HOME)/client ; ls | xargs -I {} sh -c "cp -r {}/* $(HOME)/tool"
16+
rm -rf client
17+
18+
# Clone repo
19+
clone-repo:
20+
git clone $(GIT_REPO)
21+
22+
# Generates the irx file for icp-cert-manager
23+
generate-irx:
24+
cd $(TRAVIS_BUILD_DIR)
25+
$(HOME)/tool/bin/appscan.sh prepare -oso
26+
27+
# Login to the AppScan API
28+
api-login:
29+
curl -o $(HOME)/token.json -X POST $(CONTENT_HEADER_JSON) $(ACCEPT_HEADER_JSON) -d '{"KeyId":"$(ASOC_APIKEY)", "KeySecret":"$(ASOC_SECRET)"}' $(LOGIN_URL)
30+
31+
# Uploads the irx file to the AppScan API
32+
upload-file: api-login
33+
$(eval TOKE := $(shell python getJson.py $(HOME)/token.json "Token"))
34+
$(eval AUTH := --header 'Authorization: Bearer $(TOKE)')
35+
$(eval FILE := fileToUpload=@$(shell pwd)/$(notdir $(shell find $(pwd) -maxdepth 2 -name '*.irx' -print)))
36+
37+
curl -o $(HOME)/file.json -X POST --header 'Content-Type: multipart/form-data' $(ACCEPT_HEADER_JSON) $(AUTH) -F $(FILE) $(UPLOAD_URL)
38+
39+
# Checks to see if Cert-Manager-Application already exists.
40+
# TODO: Error with the url, will come back to this later.
41+
get-app:
42+
$(eval TOKE := $(shell python getJson.py $(HOME)/token.json "Token"))
43+
$(eval AUTH := --header 'Authorization: Bearer $(TOKE)')
44+
$(eval URL := $(GET_APP_URL)'$(APP_NAME)''')
45+
46+
curl -X GET $(ACCEPT_HEADER_JSON) $(AUTH) $(URL)
47+
48+
# Assume we have an existing application, then we'll simply run the static scan
49+
run-scan:
50+
$(eval TOKE := $(shell python getJson.py $(HOME)/token.json "Token"))
51+
$(eval AUTH := --header 'Authorization: Bearer $(TOKE)')
52+
$(eval FILE_ID := "$(shell python getJson.py $(HOME)/file.json "FileId")")
53+
$(eval APP_ID := "$(shell python getJson.py app.json "Id")")
54+
55+
curl -X POST $(CONTENT_HEADER_JSON) $(ACCEPT_HEADER_JSON) $(AUTH) -d '{"ARSAFileId": $(FILE_ID), "ApplicationFileId": $(FILE_ID), "ScanName": "$(TRAVIS_TAG):$(TRAVIS_JOB_NUMBER):$(TRAVIS_COMMIT)", "EnableMailNotification": false, "Locale": "en-US", "AppId": $(APP_ID), "Execute": true, "Personal": false}' $(STATIC_SCAN_URL)
56+
57+
get-asset-group:
58+
$(eval TOKE := $(shell python getJson.py $(HOME)/token.json "Token"))
59+
$(eval AUTH := --header 'Authorization: Bearer $(TOKE)')
60+
61+
curl -o asset.json -X GET $(ACCEPT_HEADER_JSON) $(AUTH) $(GET_ASSET_GROUP_URL)
62+
63+
# Create the application only if the application doesn't already exist.
64+
create-app: get-asset-group
65+
$(eval ASSET_GROUP_ID := "$(shell python getJson.py asset.json "Id")")
66+
$(eval TOKE := $(shell python getJson.py $(HOME)/token.json "Token"))
67+
$(eval AUTH := --header 'Authorization: Bearer $(TOKE)')
68+
69+
curl -o app.json -X POST $(CONTENT_HEADER_JSON) $(ACCEPT_HEADER_JSON) $(AUTH) -d '{"Name": $(APP_NAME), "AssetGroupId": $(ASSET_GROUP_ID), "BusinessImpact": "Unspecified"}' $(CREATE_APP_URL)

appscan/app.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"Id": "121195cc-ce37-41e9-83ff-9b730d7ae969",
3+
"AssetGroupName": "IBM Watson and Cloud Platform",
4+
"DateCreated": null,
5+
"LastUpdated": null,
6+
"LastComment": null,
7+
"RiskRating": "Unknown",
8+
"CreatedBy": null,
9+
"CriticalIssues": 0,
10+
"HighIssues": 0,
11+
"MediumIssues": 0,
12+
"LowIssues": 0,
13+
"IssuesInProgress": 0,
14+
"MaxSeverity": "Undetermined",
15+
"RR_MaxSeverity": 0,
16+
"NewIssues": 0,
17+
"OpenIssues": 0,
18+
"TotalIssues": 0,
19+
"OverallCompliance": null,
20+
"ComplianceStatuses": [],
21+
"CanBeDeleted": true,
22+
"LockedToSubscription": false,
23+
"Name": "Watson Ruby SDK",
24+
"AssetGroupId": null,
25+
"BusinessImpact": "Unspecified",
26+
"Url": null,
27+
"Description": null,
28+
"BusinessUnit": null,
29+
"Type": null,
30+
"Technology": null,
31+
"TestingStatus": "NotStarted",
32+
"Hosts": null,
33+
"CollateralDamagePotential": "NotDefined",
34+
"TargetDistribution": "NotDefined",
35+
"ConfidentialityRequirement": "NotDefined",
36+
"IntegrityRequirement": "NotDefined",
37+
"AvailabilityRequirement": "NotDefined",
38+
"Tester": null,
39+
"BusinessOwner": null,
40+
"DevelopmentContact": null,
41+
"PreferredOfferingType": "None"
42+
}

appscan/getJson.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import json
2+
import sys
3+
4+
def main():
5+
data = load_data()
6+
printFields(data)
7+
8+
def load_data():
9+
data = ""
10+
filename = sys.argv[1]
11+
with open(filename, "r") as read:
12+
data = json.load(read)
13+
if isinstance(data, list):
14+
data = data[0]
15+
return data
16+
17+
def printFields(data):
18+
fields = sys.argv[2:]
19+
for i in fields:
20+
print(data[i])
21+
22+
main()

0 commit comments

Comments
 (0)