Coder Social home page Coder Social logo

devigned / pub Goto Github PK

View Code? Open in Web Editor NEW
13.0 5.0 8.0 4.56 MB

Command line for automating Azure Marketplace publishing

Home Page: https://docs.microsoft.com/en-us/azure/marketplace/cloud-partner-portal-orig/cloud-partner-portal-getting-started-with-the-cloud-partner-portal

License: MIT License

Makefile 1.68% Go 98.32%
azure iaas marketplace publishing vhd vm

pub's Introduction

Pub: cmd line for the Azure Cloud Partner Portal

Actions Status

Pub enables command line automation for working with offers on Azure Marketplace and on AppSource. For more information on the Cloud Partner Portal, check out Azure Docs.

The command line interface for pub is simply a facade over the REST API exposed by the Cloud Partner Portal.

Install

Easiest way is to use golang, but there are also precompiled binaries on the releases page.

$ go get github.com/devigned/pub
...
$ pub -h
...

Usage

From the top level, pub offers access to view and manipulate resources.

pub provides a command line interface for the Azure Cloud Partner Portal

Usage:
  pub [command]

Available Commands:
  help        Help about any command
  offers      a group of actions for working with offers
  operations  a group of actions for working with offer operations
  publishers  a group of actions for working with publishers
  skus        a group of actions for working with SKUs
  version     Print the git ref
  versions    a group of actions for working with versions

Flags:
  -v, --api-version string   the API version override (default "2017-10-31")
      --config string        config file (default is $HOME/.pub.yaml)
  -h, --help                 help for pub

Use "pub [command] --help" for more information about a command.

Object Model

  • Publishers have many offers
  • Offers can have many SKUS
  • Offers can have many operations with only one active operation
  • SKUs can have many versions

Authentication

There are two ways to authenticate to pub. Both paths use Azure Active Directory (AAD) to authenticate against the https://cloudpartner.azure.com resource URI. Using a token generated by Azure CLI is probably the easiest way to get started. When you are ready to fully automate the publication process, using a AAD Service Principal / Application will make it easier to inject environment variables into a build process.

Using an Azure Active Directory Token via Azure CLI

With the commands below, you can fetch an AAD token via Azure CLI and use it to auth calls in pub.

token=$(az account get-access-token --resource https://cloudpartner.azure.com --query "accessToken" -o tsv)
AZURE_TOKEN=$token pub publishers list

Using an AAD Application and Service Principal

Prerequisite: setup an AAD Application and Service Principal.

After setting up the AAD App / Service Principal, set the following environment variables:

export AZURE_TENANT_ID=<tenant uuid>
export AZURE_CLIENT_ID=<application / client uuid>
export AZURE_CLIENT_SECRET=<service principal secret / password>
pub publishers list

Command Output

All command output and any complex input is formatted as JSON. Definitely recommend using jq or something similar.

Publishers

Provides the ability to query the publishers.

$ ./bin/pub publishers -h
a group of actions for working with publishers

Usage:
  pub publishers [command]

Available Commands:
  list        list all publishers

Flags:
  -h, --help   help for publishers

Global Flags:
  -v, --api-version string   the API version override (default "2017-10-31")
      --config string        config file (default is $HOME/.pub.yaml)

Use "pub publishers [command] --help" for more information about a command.

$ ./bin/pub publishers list | jq
[
  {
    "id": "your-publisher-id",
    "definition": {
      "displayText": "Your Publisher Name",
      "offerTypeCategories": [
        "someCategories"
      ],
      "sellerId": 1234567
    }
  }
]

Offers

Offers is the heart of most of the Cloud Partner Portal workflow. For more details, see the marketplace offers documentation. Offers represent a marketing / description header over a set of SKUs.

To take a publication to market, run the following workflow:

put offer -> put version -> publish offer -> test offer -> live

The publish and live commands both start a long running operation which can be observed via the operations commands. There can only be 1 operation running on an offer at a time.

$ pub offers
a group of actions for working with offers

Usage:
  pub offers [command]

Available Commands:
  list        list all offers
  live        go live with an offer (make available to the world)
  publish     publish an offer
  put         create or update an offer
  show        show an offer
  status      show status for an offer
...

SKUs

A SKU, or a Plan in the REST API, contains details for a specific type of offering. For example, the SKU represents a VM Image or other specialized, versioned type under an offering.

$ pub skus
a group of actions for working with SKUs

Usage:
  pub skus [command]

Available Commands:
  list        list all SKUs for a given offer and publisher
  put         create a SKU
  show        show a SKU for a given offer
...

Versions

Versions are the lowest level resource in the marketplace. For example, in a VM Image, this would consist of the URI to the VHD media and details related to that specific version of the image.

$ pub versions
a group of actions for working with versions

Usage:
  pub versions [command]

Available Commands:
  list        list all versions for a given plan
  put         put a version for a given plan
  show        show a version for a given plan
...

Operations

Operations provide insight into the workflow and status of the publication process.

$ pub operations
a group of actions for working with offer operations

Usage:
  pub operations [command]

Available Commands:
  cancel      cancel the active operation for a given offer and print the operations
  list        list operations and optionally filter by status
  show        show an operation by Id
...

Debug Output

If you want to see more details about the HTTP requests being made, run any command with DEBUG=true.

$ DEBUG=true pub publishers list
GET /api/publishers?api-version=2017-10-31 HTTP/1.1
Host: cloudpartner.azure.com

HTTP/1.1 200 OK
Transfer-Encoding: chunked
Cache-Control: no-cache
Content-Type: application/json; charset=utf-8
Date: Sun, 03 Nov 2019 16:55:07 GMT
Expires: -1
Pragma: no-cache
Server: Microsoft-IIS/10.0
Vary: Accept-Encoding
X-Aspnet-Version: 4.0.30319
X-Content-Type-Options: nosniff
X-Ms-Correlation-Request-Id: dc12d384-6c53-4880-9b84-de1e89cbf9c7
X-Powered-By: ASP.NET

8a
[{"version":0,"id":"your-publisher-id","definition":{"displayText":"Your publisher name,"offerTypeCategories":["someCategory"],"sellerId":1234456}}]
0

[{"id":"your-publisher-id","definition":{"displayText":"Your publisher name,"offerTypeCategories":["someCategory"],"sellerId":1234456}}]

pub's People

Contributors

devigned avatar marosset avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

pub's Issues

feature request: delete version

Currently, the versions subcommand only supports putting a version. However, I'd like to be able to delete a version from a draft plan.

A future thought may be to also request deletion of a version from a live/published plan. Although reading the Azure documentation, it's not clear to me if this is supported via the exposed marketplace API.

PUT operations on offers failing with 409

Recently PUT operations have started to fail with 409 with the following error.

unable to put offer: uri: https://cloudpartner.azure.com/api/publishers/microsoft-aks/offers/aks-windows?api-version=2017-10-31, status: 409, body: {"error":{"code":"InvalidResourceId","message":"Offer ID already exists. If you wanted to update an existing offer, please ensure If-Match header is specified as per documentation."}}

Documentation at https://docs.microsoft.com/en-us/azure/marketplace/cloud-partner-portal-orig/cloud-partner-portal-api-creating-offer shows

image

After reading through the docs and inspecting API calls it looks like the cloud partner api has the following behaviors:

  • GET operations do not include an etag in the document
  • PUT operations return an etag value in the HTTP header which is a timestamp
  • Documentation recommends setting an a header with If-Match="*" for add/modify operations

Add a "put" command for SKUs

Creating new SKUs is going to be key for automating image publishing for capi, would be great to be able to create a new SKU from the CLI tool when it doesn't exist.

Versions PUT cmd gets an Internal Server 500 error

What Happened

When I run the following command:

az_pub versions put image -p vmware-inc -o tkg-capi -s k8s-1dot18dot14-ubuntu-1804 --version 2021.02.24 --vhd-uri <vhd-url>

I get the following internal server 500 error:

16:14:48  unable to put offer: uri: https://cloudpartner.azure.com/api/publishers/vmware-inc/offers/tkg-capi?api-version=2017-10-31, status: 500, body: {"Variant":{"serviceName":"Variant","error":"snapshot() resulted in an internal conflict! Retry is OK.\r\n[\r\n  \"azure-sku [variantId: edccc6b4-0e81-4af3-9d08-ada64584105d, configuration.externalId: k8s-1dot17dot11-ubuntu-1804] -- mismatch(1)\",\r\n  \"azure-sku [variantId: 66570f10-77e2-4173-810d-e75661449e05, configuration.externalId: k8s-1dot18dot8-ubuntu-1804] -- mismatch(1)\",\r\n  \"azure-sku [variantId: edb770f9-fb05-44e7-85b6-ff2e14358c35, configuration.externalId: k8s-1dot19dot1-ubuntu-1804] -- mismatch(1)\",\r\n ...

What did you expect

I expect a 200 OK status code

What have you done to debug the issue

This issue recently started occurring after this command has run successfully for months. It can be consistently reproduced locally and in our CI environment.

The interesting thing is that querying against the same marketplace API using a different client (Postman) with the same exact request header and body that I extracted from debugging the client, results in a 200 OK status. Therefore I have ruled it out to be simply a Marketplace API issue.

I've yet to see if I can reproduce this issue against a smaller offering, but I'll update this issue thread here with my findings.

Support new options in Azure Virtual Machine publishing

Microsoft recently added a property Requires custom ARM template for deployment, a checkbox that can be set while publishing images in a plan. It will be great if we have a json field similar to this that can be passed via a script instead of manually setting/unselecting it every time.

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.