Skip to content

Commit

Permalink
modify prepare-swagger.sh and configure_swagger.md
Browse files Browse the repository at this point in the history
  • Loading branch information
wemeya committed Jun 14, 2017
1 parent 6cee61c commit a091f6f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 28 deletions.
49 changes: 21 additions & 28 deletions docs/configure_swagger.md
Original file line number Diff line number Diff line change
@@ -1,24 +1,22 @@
# View and test Harbor REST API via Swagger
A Swagger file is provided for viewing and testing Harbor REST API. First, you should get the source code of Harbor:
```sh
git clone [email protected]:vmware/harbor.git
```
A Swagger file is provided for viewing and testing Harbor REST API.

### Viewing Harbor REST API
* Open the file **swagger.yaml** under the _docs_ directory in Harbor project;
* Paste all its content into the online Swagger Editor at http://editor.swagger.io. The descriptions of Harbor API will be shown on the right pane of the page.

![Swagger Editor](img/swaggerEditor.png)

### Testing Harbor REST API
From time to time, you may need to mannually test Harbor REST API. You can deploy the Swagger file into Harbor's service node.
From time to time, you may need to mannually test Harbor REST API. You can deploy the Swagger file into Harbor's service node. Suppose you install Harbor through online or offline installer, you should have a Harbor directory after you un-tar the installer, such as **~/harbor**.

**Caution:** When using Swagger to send REST requests to Harbor, you may alter the data of Harbor accidentally. For this reason, it is NOT recommended using Swagger against a production Harbor instance.

* Change the directory to _docs_ in Harbor project.
* Download _prepare-swagger.sh_ and _swagger.yaml_ under the _docs_ directory to your local Harbor directory, e.g. **~/harbor**.
```sh
cd docs
wget https://raw.githubusercontent.com/vmware/harbor/master/docs/prepare-swagger.sh https://raw.githubusercontent.com/vmware/harbor/master/docs/swagger.yaml
```
* Edit the script file _prepare-swagger.sh_ under the _docs_ directory.
* Edit the script file _prepare-swagger.sh_.
```sh
vi prepare-swagger.sh
```
Expand All @@ -30,15 +28,15 @@ From time to time, you may need to mannually test Harbor REST API. You can deplo
```sh
SERVER_ID=<HARBOR_SERVER_DOMAIN>
```
* Run the shell script. It downloads a Swagger package and extracts files into the _static_ directory in Harbor project.
* Change the file mode.
```sh
./prepare-swagger.sh
```
* Change the directory to _make_
chmod +x prepare-swagger.sh
````
* Run the shell script. It downloads a Swagger package and extracts files into the _../static_ directory.
```sh
cd ../make/dev
./prepare-swagger.sh
```
* Edit the _docker-compose.yml_ file.
* Edit the _docker-compose.yml_ file under your local Harbor directory.
```sh
vi docker-compose.yml
```
Expand All @@ -48,25 +46,20 @@ From time to time, you may need to mannually test Harbor REST API. You can deplo
ui:
...
volumes:
- ./config/ui/app.conf:/etc/ui/app.conf
- ./config/ui/private_key.pem:/etc/ui/private_key.pem
- ./common/config/ui/app.conf:/etc/ui/app.conf:z
- ./common/config/ui/private_key.pem:/etc/ui/private_key.pem:z
- /data/secretkey:/etc/ui/key:z
- /data/ca_download/:/etc/ui/ca/:z
## add two lines as below ##
- ../../src/ui/static/vendors/swagger-ui-2.1.4/dist:/go/bin/static/vendors/swagger
- ../../src/ui/static/resources/yaml/swagger.yaml:/go/bin/static/resources/yaml/swagger.yaml
- ../src/ui/static/vendors/swagger-ui-2.1.4/dist:/harbor/static/vendors/swagger
- ../src/ui/static/resources/yaml/swagger.yaml:/harbor/static/resources/yaml/swagger.yaml
...
```
* Rebuild Harbor project
* Recreate Harbor containers
```docker
docker-compose build
```
* Clean up the previous running version. NOTE: The command does not remove your existing data.
```docker
docker-compose rm
```
* Start the new Harbor build
```docker
docker-compose up
docker-compose down -v & docker-compose up -d
```

* Because a session ID is usually required by Harbor API, **you should log in first from a browser.**
* Open another tab in the same browser so that the session is shared between tabs.
* Enter the URL of the Swagger page in Harbor as below. The ```<HARBOR_SERVER>``` should be replaced by the IP address or the hostname of the Harbor server.
Expand Down
1 change: 1 addition & 0 deletions docs/prepare-swagger.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ rm -f *.tar.gz
echo "Downloading Swagger UI release package..."
wget https://github.com/swagger-api/swagger-ui/archive/v2.1.4.tar.gz -O swagger.tar.gz
echo "Untarring Swagger UI package to the static file path..."
mkdir -p ../src/ui/static/vendors
tar -C ../src/ui/static/vendors -zxf swagger.tar.gz swagger-ui-2.1.4/dist
echo "Executing some processes..."
sed -i.bak 's/http:\/\/petstore\.swagger\.io\/v2\/swagger\.json/'$SCHEME':\/\/'$SERVER_IP'\/static\/resources\/yaml\/swagger\.yaml/g' \
Expand Down

0 comments on commit a091f6f

Please sign in to comment.