azurearm

package
v1.6.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 29, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package azurearm provides shared HTTP wire-format helpers for Azure Resource Manager (ARM) JSON REST handlers.

ARM URLs share a common shape:

/subscriptions/{sub}/resourceGroups/{rg}/providers/{provider}/{type}/{name}
/subscriptions/{sub}/resourceGroups/{rg}/providers/{provider}/{type}
/subscriptions/{sub}/providers/{provider}/{type}

and an `api-version` query parameter is always present. Real ARM responses are JSON; errors carry an `error.code` / `error.message` envelope.

Index

Constants

View Source
const ContentType = "application/json"

ContentType is the JSON content type used by all ARM responses.

View Source
const MaxBodyBytes = 1 << 20

MaxBodyBytes caps incoming JSON request bodies. Real ARM PUT requests for a VM are ~3 KB; 1 MiB is plenty of headroom.

Variables

This section is empty.

Functions

func BuildResourceID

func BuildResourceID(subscription, resourceGroup, provider, resourceType, name string) string

BuildResourceID constructs an ARM resource ID for the given path components. Used in response bodies so SDKs receive properly-shaped IDs.

func DecodeJSON

func DecodeJSON(w http.ResponseWriter, r *http.Request, v any) bool

DecodeJSON reads a JSON request body into v. Returns false (and writes a 400) on decode error.

func WriteCErr

func WriteCErr(w http.ResponseWriter, err error)

WriteCErr maps a CloudEmu canonical error to the matching ARM HTTP status and code. Used by handlers so error mapping is consistent across services.

func WriteError

func WriteError(w http.ResponseWriter, status int, code, msg string)

WriteError writes an ARM-style JSON error response.

func WriteJSON

func WriteJSON(w http.ResponseWriter, status int, v any)

WriteJSON writes v as a JSON response with status code.

Types

type ResourcePath

type ResourcePath struct {
	Subscription    string
	ResourceGroup   string
	Provider        string // e.g. "Microsoft.Compute"
	ResourceType    string // e.g. "virtualMachines" or "locations"
	ResourceName    string // empty for collection paths
	SubResource     string // e.g. "start", "powerOff", "operationStatuses"
	SubResourceName string // e.g. operation GUID for .../operationStatuses/{id}
}

ResourcePath is a parsed ARM URL path. Fields are empty when not present in the path (e.g., a subscription-scoped list has no ResourceGroup).

func ParsePath

func ParsePath(urlPath string) (ResourcePath, bool)

ParsePath extracts the ARM path components from urlPath. Returns ok=false when the path doesn't look like an ARM resource URL.

Recognized shapes:

/subscriptions/{sub}
/subscriptions/{sub}/resourceGroups/{rg}
/subscriptions/{sub}/providers/{prov}/{type}
/subscriptions/{sub}/resourceGroups/{rg}/providers/{prov}/{type}
/subscriptions/{sub}/resourceGroups/{rg}/providers/{prov}/{type}/{name}
/subscriptions/{sub}/resourceGroups/{rg}/providers/{prov}/{type}/{name}/{subResource}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL