Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DOCS-143] Use case: Create an asset with our API #145

Draft
wants to merge 11 commits into
base: main
Choose a base branch
from

Conversation

mjang-cobalt
Copy link
Contributor

@ana-dashuk-cobalt I'd appreciate your thoughts on my first draft. Is it understandable? Would you be able to use it?

I think I want to update / add several things, including:

  • Set up common text as variables
  • Maybe even set up names of tokens as variables

Possibly:

  • Set up some sections as variables, to help us reuse them for different use cases
  • Move common content, specifically "Create an API Token in the Cobalt UI" and "Use the API Token to Authorize Access to the _index.md file
  • Figure out how to set up a "copy" icon for the curl commands

@mjang-cobalt mjang-cobalt self-assigned this Jul 21, 2022
@mjang-cobalt mjang-cobalt marked this pull request as draft July 21, 2022 19:51
@netlify
Copy link

netlify bot commented Jul 21, 2022

Deploy Preview for cobalt-docs ready!

Name Link
🔨 Latest commit 65da5b7
🔍 Latest deploy log https://app.netlify.com/sites/cobalt-docs/deploys/62debfc148fbe400084ca77f
😎 Deploy Preview https://deploy-preview-145--cobalt-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

If you add a `| jq .` to the end of your REST call, you may find it easier to
read the output:

```
Copy link
Contributor

@ana-dashuk-cobalt ana-dashuk-cobalt Jul 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

```json


Without the `| jq.`, you may have output that looks like:

```
Copy link
Contributor

@ana-dashuk-cobalt ana-dashuk-cobalt Jul 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

```json

This highlights the syntax.

linkTitle: "Create an Asset"
weight: 110
description: >
Use this sequence of REST calls to create an asset.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Send this sequence...

Use is repeated 3 times.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm using "Run this sequence..."

@@ -0,0 +1,229 @@
---
title: "Use Our API to Create an Asset"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Option: Create an Asset via the API

Since we'll add more guides to this section, I would start the title with an action and then add "Using the API" or "via the API." At the same time, if we repeat it in each guide, this will be redundant.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the same time, if we repeat it in each guide, this will be redundant.

Good point. Since this book already has API in the name, I'm going to limit such titles -- in this case "Create an Asset"

btw, the Google Developer Style guide suggests that we should not use via

---

{{% pageinfo %}}
The pages in this book describe how you can use our API to manage your Assets
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assets

We discussed the capitalization for assets this week.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The pages in this book describe how you can use our API to manage your Assets
The pages in this book describe how you can use our API to manage your assets

---

{{% pageinfo %}}
The pages in this book describe how you can use our API to manage your Assets
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we'll add more guides to this section (not only about assets or pentests), maybe we can make the sentence more generic? Something like:

The pages in this book describe how you can use our API to interact with the Cobalt platform.

The pages in this book describe how you can work with the Cobalt platform using the API.

Next, you can use the API Token to authorize access to our other endpoints. Take
the API Token that you [generated](#create-an-api-token-in-the-cobalt-ui). Substitute that value for `YOUR-PERSONAL-API-TOKEN`:

```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

```c

With c, the syntax is highlighted properly, but nothing happens when I try curl or cURL.

<!-- Future task: set up variables for `YOUR-PERSONAL-API-TOKEN` and
`YOUR-V2-ORGANIZATION-TOKEN`. May support automated populating of REST calls. -->

This page describes how you can use our API To create an [asset](../../getting-started/glossary/#asset).
Copy link
Contributor

@ana-dashuk-cobalt ana-dashuk-cobalt Jul 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to

We can remove this sentence, the same information is given earlier.

{{%expand "Review sample output." %}}
You should see output similar to:

```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

```json


You can create an [asset](../getting-started/glossary/#asset) with the following REST call:

```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

```c

To add or modify or information related to your asset, you'll need the asset ID.
You can find this ID with the REST call to [Get All Assets](https://docs.cobalt.io/v2/#get-all-assets):

```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

```c

reference to [Get All Assets](https://docs.cobalt.io/v2/#get-all-assets).

{{% expand "Review sample output." %}}
```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

```json

information with the following REST call:


```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

```c

As an example, the following command uploads the `image.jpg` file as asset
documentation:

```
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

```c

Comment on lines 28 to 29
Save the API Token. After you exit the modal, you won't see the full token again.
If you lose it, you may have to revoke the token and start over.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Save the API token. After you close the overlay, you won't see the full token again.
If you lose it, you may have to revoke the token and start again.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will accept. I searched for instances of both, and "close the overlay" is 4x more popular than "exit the modal".

Save the API Token. After you exit the modal, you won't see the full token again.
If you lose it, you may have to revoke the token and start over.

Substitute the API Token for `YOUR-PERSONAL-API-TOKEN` in the REST calls
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

token

Comment on lines 36 to 37
Next, you can use the API Token to authorize access to our other endpoints. Take
the API Token that you [generated](#create-an-api-token-in-the-cobalt-ui). Substitute that value for `YOUR-PERSONAL-API-TOKEN`:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Next, you can use the API token to authorize in the Cobalt API. Take
the API token that you generated. Substitute that value for YOUR-PERSONAL-API-TOKEN:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW, when I disable 2FA for an account, I've found REST calls to sign in and create an API token. But, those REST calls are not part of the Cobalt API. So I'm going to change this to

...

Next, you can use the API token to authorize access to the Cobalt API. Take
the API token that you generated. Substitute that value for YOUR-PERSONAL-API-TOKEN:

{
"resource": {
"id": "some_id",
"name": "Saxophone - Alto",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the ideal world, we should have an organization to use in examples, such as Example Organization.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh gosh -- I really should change this to something that sounds more serious!

-v
```

For more information on each parameter, see our API Reference documentation on
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API reference

how to [Create an Asset](https://docs.cobalt.io/v2/#create-an-asset).

The command we use includes a `-v`, which sets up output in verbose mode. The
command works without it; however, you would see no response from the REST call.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

command works without it. However, you would see no response from the REST call.

| Message | Meaning |
|------------|------------------|
| HTTP/2 201 | Asset created |
| HTTP/2 401 | No asset created. Check the value of your API Token|
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

API token

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm thinking -- maybe we should PR the API reference to include this list (and rename Errors to "HTTP responses" or "HTTP response codes"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But later....

|------------|------------------|
| HTTP/2 201 | Asset created |
| HTTP/2 401 | No asset created. Check the value of your API Token|
| HTTP/2 404 | No asset created. Check the value of YOUR-V2-ORGANIZATION-TOKEN|
Copy link
Contributor

@ana-dashuk-cobalt ana-dashuk-cobalt Jul 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

YOUR-V2-ORGANIZATION-TOKEN

I also get 422 when enter an invalid org token.


## Find Your Asset ID

To add or modify or information related to your asset, you'll need the asset ID.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To add or modify the information

If you've set up more than one Asset, you may need to search through the output.
For more information about each Asset response field, see our API documentation
reference to [Get All Assets](https://docs.cobalt.io/v2/#get-all-assets).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If your organization has more than 10 assets, you can add the limit parameter to the request URL to retrieve more entries.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I might set that up as a separate note

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've addressed this in current lines 136-139

(You can use limit with any number -- the link includes "5" as an example:

"If specified, returns only a specified amount of assets, e.g. https://api.cobalt.io/assets?limit=5"

-H "Accept: application/vnd.cobalt.v2+json" \
-H "Authorization: Bearer YOUR-PERSONAL-API-TOKEN" \
-H "X-Org-Token: YOUR-V2-ORGANIZATION-TOKEN" \
| jq .
Copy link
Contributor

@ana-dashuk-cobalt ana-dashuk-cobalt Jul 22, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also filter assets by their title and id by adding the following jq command:
| jq -r ".data[] | .resource | .title, .id"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoa! I didn't know this!

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not an expert on this topic. I will educate myself more on jq. Some responses are too long to include them in documentation, so this can be beneficial.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should be a way to retrieve an ID for a specific asset by its name, but I don't know the syntax for this command. 🙁

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MVC. Your suggestion is an improvement over mine.

FWIW, I've set up your suggestion as a "tip", current lines 141-144

{{% /expand %}}

If you've set up more than one asset, you'll see the `id` in the same
code block as the `title`, which you may have used to [create the asset](#create-an-asset).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

object as the title


| Message | Meaning |
|------------|------------------|
| HTTP/2 201 | Asset created |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

| HTTP/2 204 | Asset updated |


## Include an Asset Attachment

You can help our pentesters by including images or even PDFs. As noted in our
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PDF files

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's time to set up another variable, to list the same attachments on this page, and in https://developer.cobalt.io/getting-started/assets/asset-description/

## Include an Asset Attachment

You can help our pentesters by including images or even PDFs. As noted in our
[Asset Documentation](../getting-started/assets/asset-description/#asset-documentation),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(../../getting-started/assets/asset-description/#asset-documentation)

@mjang-cobalt
Copy link
Contributor Author

@ana-dashuk-cobalt thanks so much for your detailed review. I'm going to push an update that addresses most of your questions. But first, I'm going to add comments when I don't agree with something. (And I need to research the list of supported languages for code -- I think of

```c

For a C language code sample, ref https://github.com/rouge-ruby/rouge/wiki/List-of-supported-languages-and-lexers

@mjang-cobalt
Copy link
Contributor Author

mjang-cobalt commented Jul 22, 2022

Hugo has a list of "lexers" https://gohugo.io/content-management/syntax-highlighting/#list-of-chroma-highlighting-languages. Based on that list,```bash seems to work better.

@mjang-cobalt
Copy link
Contributor Author

@ana-dashuk-cobalt once you've given your "OK" to this, I'm going to set up a new PR for developer review(s).

We might reorganize this later. Examples:

  • Include common REST calls in the _index.md page
  • Set up variables for common REST calls for different use cases

Comment on lines +147 to +164
```json
{
"data": {
"resource": {
"id": "YOUR-ASSET-IDENTIFIER",
"title": "Test Asset",
"description": "How to describe the asset to our pentesters",
"asset_type": "web",
"logo": null,
"attachments": []
},
"links": {
"ui": {
"url": "https://api.cobalt.io/links/<endpoint for the asset>"
}
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
```json
{
"data": {
"resource": {
"id": "YOUR-ASSET-IDENTIFIER",
"title": "Test Asset",
"description": "How to describe the asset to our pentesters",
"asset_type": "web",
"logo": null,
"attachments": []
},
"links": {
"ui": {
"url": "https://api.cobalt.io/links/<endpoint for the asset>"
}
}
}
}

YOUR-ASSET-TITLE
YOUR-ASSET-IDENTIFIER

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I chose "Test Asset" to match the name I used to create the asset.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants