Skip to content

Commit

Permalink
fix: software as a service, package build|verify (#203)
Browse files Browse the repository at this point in the history
* deleting image file at root of repo

* adding script

* fixing software as a service results

* version 0.2.2

* style and linter fixes

* Fixing #202

* style and linter fixes
  • Loading branch information
kevinhillinger committed Jun 16, 2023
1 parent 0113ff4 commit 3ad2c8a
Show file tree
Hide file tree
Showing 17 changed files with 127 additions and 21 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ coverage.xml
*.py,cover
.hypothesis/
.pytest_cache/
.cnab

# Translations
*.mo
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@ def load_help():
examples:
- name: List the media for an offer's listing
text: |-
az partnercenter marketplace offer listing media list --offer-id MyOfferId
az partnercenter marketplace offer listing media list --offer-id MyOfferId --type Image
"""
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@
import yaml
from knack.util import CLIError

DATA_DIR = "/data"


def verify(manifest_file):
container = _get_container(manifest_file)
result = container.exec_run('cpa verify --directory ./cpaMount')
vr = VerifyResult(result.output.decode("utf-8"))
return vr.to_list()
result = container.exec_run('cpa verify', workdir=DATA_DIR)
return result


def bundle(manifest_file):
container = _get_container(manifest_file)
acr_name = _get_acr_name(manifest_file)
result = container.exec_run('az acr login -n ' + acr_name)
result = container.exec_run('cpa buildbundle', workdir='/cpaMount')
result = container.exec_run('cpa buildbundle', workdir=DATA_DIR)
return result


Expand All @@ -48,7 +49,10 @@ def _run_container(container_name, mount_path):

img = 'mcr.microsoft.com/container-package-app:latest'
cmd = 'sleep infinity'
volumes = ['/var/run/docker.sock:/var/run/docker.sock', f'{mount_path}:/cpaMount', f'{absolute_path}:/root/.azure']

print(mount_path)

volumes = ['/var/run/docker.sock:/var/run/docker.sock', f'{mount_path}:/data', f'{absolute_path}:/root/.azure']
container = client.containers.run(img, cmd, detach=True, volumes=volumes, name=container_name)
return container

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@


def build_package(client, offer_id, manifest_file=None):
_execute_action_by_offer_type(client, offer_id, lambda: _build_cnab_bundle(manifest_file))
return _execute_action_by_offer_type(client, offer_id, manifest_file, _build_cnab_bundle)


def verify_package(client, offer_id, manifest_file=None):
_execute_action_by_offer_type(client, offer_id, lambda: _verify_cnab_bundle(manifest_file))
return _execute_action_by_offer_type(client, offer_id, manifest_file, _verify_cnab_bundle)


def _execute_action_by_offer_type(client, offer_id, action):
def _execute_action_by_offer_type(client, offer_id, manifest_file, action):
offer = client.get(offer_id)
if offer is None:
raise ResourceNotFoundError('An Offer was not found with that ID.', 'Please check the value set for parameter --offer-id.')
Expand All @@ -30,20 +30,22 @@ def _execute_action_by_offer_type(client, offer_id, action):
offer_setup = client.get_setup(offer_id)
# if the offer type is "AzureApplication" AND the offer is setup to sell through Microsoft, we can build a CNAB bundle for it
if offer_setup.sell_through_microsoft:
action()
else:
raise InvalidArgumentValueError(f'{offer_id} offer is not setup to support a CNAB bundle. The offer type must be {OfferType.AZUREAPPLICATION} and setup to sell through Microsoft',
f'Update the offer\'s setup to sell through Microsoft.\n\n az partercenter marketplace offer setup --offer-id {offer_id} --sell-through-microsoft')
return action(manifest_file)

raise InvalidArgumentValueError(f'{offer_id} offer is not setup to support a CNAB bundle. The offer type must be {OfferType.AZUREAPPLICATION} and setup to sell through Microsoft',
f'Update the offer\'s setup to sell through Microsoft.\n\n az partercenter marketplace offer setup --offer-id {offer_id} --sell-through-microsoft')

# if we got to this point, the offer type isn't supported
raise CLIError(f'{offer_id} offer is a {offer_type} type which is currently not supported by the CLI. Please submit an issue to get support at {ISSUES_URL}.')


def _verify_cnab_bundle(manifest_file):
result = verify(manifest_file)
print(result.output.decode("utf-8"))
return result


def _build_cnab_bundle(manifest_file):
result = bundle(manifest_file)
return result.output
print(result.output.decode("utf-8"))
return result
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,8 @@ def load_help():
type: command
short-summary: Adds a package to the technical configuration of a plan
"""

helps['partnercenter marketplace offer plan technical-configuration package delete'] = """
type: command
short-summary: Deletes a package to the technical configuration of a plan
"""
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ def load_arguments(commands_loader, _):
c.argument('tag', arg_group='CNAB Resource', options_list=['--tag'], help='The name of the image repository.')
c.argument('digest', arg_group='CNAB Resource', options_list=['--digest'], help='The digest of the bundle with a format of sha256:<hashcode>')

with commands_loader.argument_context('partnercenter marketplace offer plan technical-configuration delete') as c:
with commands_loader.argument_context('partnercenter marketplace offer plan technical-configuration package delete') as c:
c.argument('repository_name', arg_group='CNAB Resource', options_list=['--repository'], help='The name of the image repository in the Azure Container Registry.')
c.argument('tag', arg_group='CNAB Resource', options_list=['--tag'], help='The name of the image repository.')
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"extensionResourceName": {
"type": "string",
"metadata": {
"description": "resource name of the extension"
}
},
"resourceName": {
"type": "string",
"metadata": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ restrictions:
helmChart: "./azure-vote"
clusterArmTemplate: "./mainTemplate.json"
uiDefinition: "./createUIDefinition.json"
registryServer: "youracr.azurecr.io"
registryServer: "thfalgoupartner.azurecr.io"
extensionRegistrationParameters:
defaultScope: "cluster"
namespace: "contoso"
billingIdentifier: microsoft.marketplace.example.azure-vote

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ class MicrosoftIngestionApiModelsProductsAzureProduct(ModelComposed):

allowed_values = {
('resource_type',): {
'SOFTWAREASASERVICE': "SoftwareAsAService",
'AZUREAPPLICATION': "AzureApplication",
'AZUREDEVELOPERSERVICE': "AzureDeveloperService",
'AZURETHIRDPARTYVIRTUALMACHINE': "AzureThirdPartyVirtualMachine",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ class MicrosoftIngestionApiModelsProductsAzureProductAllOf(ModelNormal):

allowed_values = {
('resource_type',): {
'SOFTWAREASASERVICE': "SoftwareAsAService",
'AZUREAPPLICATION': "AzureApplication",
'AZUREDEVELOPERSERVICE': "AzureDeveloperService",
'AZURETHIRDPARTYVIRTUALMACHINE': "AzureThirdPartyVirtualMachine",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class MicrosoftIngestionApiModelsProductsBaseProduct(ModelComposed):
'MANAGEDCONSUMABLE': "ManagedConsumable",
'SEASONPASS': "SeasonPass",
'SUBSCRIPTION': "Subscription",
'SOFTWAREASASERVICE': "SoftwareAsAService",
'AZUREAPPLICATION': "AzureApplication",
'AZUREDEVELOPERSERVICE': "AzureDeveloperService",
'AZURETHIRDPARTYVIRTUALMACHINE': "AzureThirdPartyVirtualMachine",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class MicrosoftIngestionApiModelsProductsBaseProductAllOf(ModelNormal):
'MANAGEDCONSUMABLE': "ManagedConsumable",
'SEASONPASS': "SeasonPass",
'SUBSCRIPTION': "Subscription",
'SOFTWAREASASERVICE': "SoftwareAsAService",
'AZUREAPPLICATION': "AzureApplication",
'AZUREDEVELOPERSERVICE': "AzureDeveloperService",
'AZURETHIRDPARTYVIRTUALMACHINE': "AzureThirdPartyVirtualMachine",
Expand Down
2 changes: 1 addition & 1 deletion partnercenter/azext_partnercenter/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# --------------------------------------------------------------------------------------------


VERSION = "0.2.1"
VERSION = "0.2.2"
84 changes: 84 additions & 0 deletions scripts/release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#!/bin/bash

# required tools:
# - git CLI
# - github CLI (brew install gh)
#
# to login using the GH CLI:
# gh auth login -h github.com -p ssh --web
# , then follow prompts
#
# example call:
# ./scripts/release.sh 0.2.2 v0.2.2-alpha

version_number=$1
version_tag=$2

function confirm_prompt() {
text=$1
read -p "$text (Y/n)" -n 1 -r
echo # (optional) move to a new line
if [[ ! $REPLY =~ ^[Yy]$ ]]
then
echo "aborting."
exit 1
fi
}

function print_info() {
echo ""
echo "Release Information:"
echo "-------------------------------"
echo "Number: $version_number"
echo "Tag: $version_tag"
echo ""

confirm_prompt "Proceed with release?"
}

function install_github_cli() {
gh_version=$(gh version)
if [[ -z "$gh_version" ]]; then
echo "GitHub CLI not installed. Installing..."
brew install gh
fi

gh_version=$(gh version)
echo "GitHub CLI installed [$gh_version]"
echo ""
}

function git_tag_version() {
confirm_prompt "Proceed with Git tag?"

echo "tagging: $version_tag"
# git tag -a $version_tag -m "$version_tag"

# echo "pushing tag: $version_tag"
# git push origin $version_tag
}

function release_extension() {
echo "building extension."
azdev extension build partnercenter


whl_file=partnercenter-$version_number-py3-none-any.whl
title="Partner Center Azure CLI Extension $version_tag"

echo "creating GitHub release."
gh release create $version_tag ./dist/$whl_file --generate-notes --draft --prerelease

echo "updating Azure CLI index"
whl_uri=https://github.com/Azure/partnercenter-cli-extension/releases/download/$version_tag/$whl_file

azdev extension update-index $whl_uri
}

print_info
install_github_cli
git_tag_version

# install_github_cli
# tag_version
# release_extension
Binary file removed video.png
Binary file not shown.

0 comments on commit 3ad2c8a

Please sign in to comment.