Skip to content

Commit

Permalink
write plugin index and order builder docs
Browse files Browse the repository at this point in the history
  • Loading branch information
sylviamoss committed Mar 16, 2021
1 parent ce3b361 commit d156681
Show file tree
Hide file tree
Showing 15 changed files with 366 additions and 314 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v2
with:
go-version: 1.15
go-version: 1.16
- name: Describe plugin
id: plugin_describe
run: echo "::set-output name=api_version::$(go run . describe | jq -r '.api_version')"
Expand Down
16 changes: 8 additions & 8 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ builds:
post:
# This will check plugin compatibility against latest version of Packer
- cmd: |
go install github.com/hashicorp/packer/cmd/packer-plugins-check &&
go install github.com/hashicorp/packer/cmd/packer-plugins-check@latest &&
packer-plugins-check -load={{ .Name }}
dir: "{{ dir .Path}}"
flags:
Expand All @@ -29,7 +29,7 @@ builds:
goarch:
- amd64
binary: '{{ .ProjectName }}_v{{ .Version }}_{{ .Env.API_VERSION }}_{{ .Os }}_{{ .Arch }}'
-
-
mod_timestamp: '{{ .CommitTimestamp }}'
flags:
- -trimpath #removes all file system paths from the compiled executable
Expand All @@ -52,15 +52,15 @@ builds:
goarch: amd64
binary: '{{ .ProjectName }}_v{{ .Version }}_{{ .Env.API_VERSION }}_{{ .Os }}_{{ .Arch }}'
archives:
- format: zip
name_template: '{{ .ProjectName }}_v{{ .Version }}_{{ .Env.API_VERSION }}_{{ .Os }}_{{ .Arch }}'
- format: zip
name_template: '{{ .ProjectName }}_v{{ .Version }}_{{ .Env.API_VERSION }}_{{ .Os }}_{{ .Arch }}'
checksum:
name_template: '{{ .ProjectName }}_v{{ .Version }}_SHA256SUMS'
algorithm: sha256
signs:
- artifacts: checksum
args:
# if you are using this is in a GitHub action or some other automated pipeline, you
# if you are using this is in a GitHub action or some other automated pipeline, you
# need to pass the batch flag to indicate its not interactive.
- "--batch"
- "--local-user"
Expand All @@ -70,7 +70,7 @@ signs:
- "--detach-sign"
- "${artifact}"
release:
# If you want to manually examine the release before its live, uncomment this line:
# draft: true
# If you want to manually examine the release before its live, uncomment this line:
# draft: true
changelog:
skip: true
skip: true
2 changes: 1 addition & 1 deletion builder/order/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
type Config struct {
packercommon.PackerConfig `mapstructure:",squash"`
common.AuthConfig `mapstructure:",squash"`
Item []OrderItem `mapstructure:"item,omitempty" required:"true"`
Item []OrderItem `mapstructure:"item" required:"true"`
}

type OrderItem struct {
Expand Down
49 changes: 49 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# HashiCups Plugin

The Hashicups plugin is part of the [Packer](https://learn.hashicorp.com/packer) Learn collection.
The plugin interacts with the [HashiCorp Demo App API](https://github.com/hashicorp-demoapp/product-api-go) called HashiCups.
The component of this plugin are:

- [Order builder](/docs/builders/order.mdx) - The order builder is used to create custom HashiCups order.

- [Toppings provisiner](/docs/provisioners/toppings.mdx) - The toppings provisioner is used add toppings to your order coffee(s).

- [Receipt post-processor](/docs/post-processors/receipt.mdx) - The receipt post-processor is used to
print the receipt of your order.

- [Coffees data source](/docs/datasources/coffees.mdx) - The coffees data source is used to
fetch all the coffees ids existent in the Hashicups menu.

- [Ingredients data source](/docs/datasources/ingredients.mdx) - The ingredients data source is used to
fetch the ingredients ids for an existent coffee in the Hashicups menu.

## The HashiCups Menu and orders

Get the available coffees:
```shell
$ curl -v localhost:19090/coffees | jq
```

The following api call requires authorization.

First, sing in with previously created account:
```shell
$ curl -X POST localhost:19090/signin -d '{"username":"education", "password":"test123"}'
```

Then, export the return JWT token to HASHICUPS_TOKEN:
```shell
$ export HASHICUPS_TOKEN=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2MTU5ODcxNzgsInVzZXJfaWQiOjEsInVzZXJuYW1lIjoiZWR1Y2F0aW9uIn0.VJQXoxror-_ZUoNHtsG6GJ-bJCOvjU5kMZtXhSzBtP0
```
With that, you can perform authorized calls.

Get the ingredients for a coffee:

````shell
$ curl -X GET -H "Authorization: ${HASHICUPS_TOKEN}" localhost:19090/coffees/1/ingredients | jq
````

Get the created orders:
```shell
$ curl -X GET -H "Authorization: ${HASHICUPS_TOKEN}" localhost:19090/orders | jq
```
63 changes: 0 additions & 63 deletions docs/builders/builder-name.mdx

This file was deleted.

88 changes: 88 additions & 0 deletions docs/builders/order.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
---
description: >
The order builder is used to create used to create custom HashiCups order.
page_title: Order - Builders
sidebar_title: Order
---

# Order

Type: `order`

The order builder is used to create used to create custom HashiCups order. A custom order is when you want to change
an ingredient quantity from one of the original coffees from the Hashicups menu. See [Example Usage](#example-usage) to
understand better how it works.

### Required

- `username` (string) - The username signed up to the Product API.
- `password` (string) - The password signed up to the Product API.
- `item` ([]OrderItem) - An item you would like to order. See the [order item configuration](#order-item-configuration).

### Optional

- `host` (string) - The Product API host. Defaults to `localhost:19090`

## Order item configuration

### Required

- `coffee` ([]Coffee) - The item's coffee. See the [coffee configuration](#coffee-configuration).


### Optional

- `quantity` (int) - How many of the item you would like to order. Defaults to `1`.

## Coffee configuration

### Required

- `id` (string) - The id of the coffee you would like to customize. The ID should exist in the Hashicups menu.
- `name` (string) - The name of your customization. Should be different from the original coffee's name.
- `ingredient` ([]Ingredient) - The ingredients you'd like to change the quantity of.
See the [ingredient configuration](#ingredient-configuration).

## Ingredient configuration

### Required

- `id` (string) - The id of the coffee ingredient you would like to customize. The ID should exist in the Hashicups menu.
- `quantity` (int) - The new quantity amount you'd like your coffee to have from the ingredient.


### Example Usage

In the Hashicups menu you can find a Packer Spiced Latter (id 1) with **40ml** of espresso (id 1) and **300ml** of semi skimmed milk (id 2).
Let's pretend you want to customized it to have **50ml** of espresso and **200ml** of semi skimmed milk instead. Also, you would like
to order two of that.
Your packer configuration will be:

```hcl
source "hashicups-order" "my-custom-order" {
username = "education"
password = "test123"
item {
coffee {
id = 1
name = "My Custom Packer Spiced Latter"
ingredient {
id = 1
quantity = 50
}
ingredient {
id = 2
quantity = 200
}
}
quantity = 2
}
}
build {
sources = ["sources.hashicups-order.my-custom-order"]
}
```


62 changes: 62 additions & 0 deletions docs/datasources/coffees.mdx
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
---
description: >
The coffees data source is used to
fetch all the coffees ids existent in the Hashicups menu.
page_title: Coffees - Data Sources
sidebar_title: Coffees
---

# Coffees

Type: `coffees`

The coffees data source is used to fetch all the coffees ids existent in the Hashicups menu.

### Required

- `username` (string) - The username signed up to the Product API.
- `password` (string) - The password signed up to the Product API.

### Optional

- `host` (string) - The Product API host. Defaults to `localhost:19090`

### OutPut

- `map` (map[string]string) - A map of coffee name to coffee id.

### Example Usage


```hcl
data "hashicups-coffees" "coffees" {
username = "education"
password = "test123"
}
locals {
vagrante_espresso = data.hashicups-coffees.coffees.map["Vagrante espresso"]
}
source "hashicups-order" "my-custom-order" {
username = "education"
password = "test123"
item {
coffee {
id = local.vagrante_espresso
name = "my custom vagrante"
ingredient {
id = 1
quantity = 50
}
}
}
}
build {
sources = ["sources.hashicups-order.my-custom-order"]
}
```


Loading

0 comments on commit d156681

Please sign in to comment.