|
| 1 | +# STACKIT Marketplace Reference Code in Golang |
| 2 | + |
| 3 | +This Golang reference code exemplifies how to integrate with the STACKIT Marketplace API as a vendor, showing the essential flow of authenticating and handling marketplace subscriptions. |
| 4 | + |
| 5 | +## Overview |
| 6 | + |
| 7 | +This example application demonstrates three key marketplace integration steps: |
| 8 | + |
| 9 | +1. **Token Validation**: Validates marketplace tokens using public key cryptography |
| 10 | +2. **Customer Resolution**: Retrieves customer information from subscription tokens |
| 11 | +3. **Subscription Approval**: Processes and approves marketplace subscriptions |
| 12 | + |
| 13 | +## Prerequisites |
| 14 | + |
| 15 | +- Go 1.18 or higher |
| 16 | +- A STACKIT Service Account Key |
| 17 | +- A marketplace token (`x-stackit-marketplace`) received via the vendor's redirect URL |
| 18 | + |
| 19 | +## Getting Started |
| 20 | + |
| 21 | +1. Clone this repository |
| 22 | +2. Set up authentication with the STACKIT Go SDK (see [Using the STACKIT Go SDK](#using-the-stackit-go-sdk) below) |
| 23 | +3. Set the following environment variables: |
| 24 | + |
| 25 | + - `MP_REF_CODE_REDIRECT_TOKEN`: The `x-stackit-marketplace` token received during redirect |
| 26 | + - `MP_REF_CODE_VENDOR_PROJECT_ID`: Your vendor STACKIT project ID associated with the product |
| 27 | + |
| 28 | +4. Run the application using either: |
| 29 | + |
| 30 | +```bash |
| 31 | +make run |
| 32 | +``` |
| 33 | + |
| 34 | +or |
| 35 | + |
| 36 | +```bash |
| 37 | +go run cmd/main.go |
| 38 | +``` |
| 39 | + |
| 40 | +## Flow Explanation |
| 41 | + |
| 42 | +The application demonstrates the following flow: |
| 43 | + |
| 44 | +1. **Marketplace token validation**: Validates the marketplace token by: |
| 45 | + - Fetching the public key from STACKIT |
| 46 | + - Validating the token format |
| 47 | + - Verifying the token signature |
| 48 | +2. **Customer Resolution**: Uses the validated token to resolve customer information |
| 49 | +3. **Subscription Approval**: Approves the marketplace subscription |
| 50 | + |
| 51 | +## Project Structure |
| 52 | + |
| 53 | +```bash |
| 54 | +. |
| 55 | +├── cmd/ |
| 56 | +│ └── main.go # Application entry point |
| 57 | +├── internal/ |
| 58 | +│ ├── step_1_validate_token.go # Token validation logic |
| 59 | +│ ├── step_2_resolve_customer.go # Customer resolution logic |
| 60 | +│ └── step_3_approve_subscription.go # Subscription approval logic |
| 61 | +├── utils/ # Utility functions |
| 62 | +│ └── utils.go |
| 63 | +``` |
| 64 | + |
| 65 | +## Development |
| 66 | + |
| 67 | +The project includes several make targets for development: |
| 68 | + |
| 69 | +```bash |
| 70 | +make build # Build the application |
| 71 | +make test # Run tests |
| 72 | +make lint # Run linter |
| 73 | +make fmt # Format code |
| 74 | +make clean # Clean build artifacts |
| 75 | +``` |
| 76 | + |
| 77 | +## Using the STACKIT Go SDK |
| 78 | + |
| 79 | +The examples in this repository use the official [STACKIT Go SDK](https://github.com/stackitcloud/stackit-sdk-go) to interact with the Marketplace API. |
| 80 | + |
| 81 | +Authentication is handled automatically by the SDK using its default configuration. For details, see the SDK's [Authentication documentation](https://github.com/stackitcloud/stackit-sdk-go?tab=readme-ov-file#authentication). |
| 82 | + |
| 83 | +A **potential** way to authenticate is by setting one of these environment variables: |
| 84 | + |
| 85 | +- `STACKIT_SERVICE_ACCOUNT_KEY`: Your service account key |
| 86 | +- `STACKIT_SERVICE_ACCOUNT_KEY_PATH`: Path to a file containing your service account key |
| 87 | +- `STACKIT_SERVICE_ACCOUNT_TOKEN`: Your service account access token |
| 88 | + |
| 89 | +## Contributing |
| 90 | + |
| 91 | +Feel free to submit issues and enhancement requests! |
0 commit comments