godep

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Apr 9, 2024 License: MIT Imports: 9 Imported by: 8

Documentation

Overview

Package godep provides Go methods and structures for talking to individual DEP API endpoints.

Index

Constants

View Source
const (
	UserAgent = "nanodep-g-o-dep/0"
)

Variables

This section is empty.

Functions

func IsCursorExhausted

func IsCursorExhausted(err error) bool

IsCursorExhausted returns true if err is a DEP "exhausted cursor" error.

func IsCursorExpired

func IsCursorExpired(err error) bool

IsCursorExpired returns true if err is a DEP "expired cursor" error. Per Apple this indicates the cursor is older than 7 days.

func IsCursorInvalid

func IsCursorInvalid(err error) bool

IsCursorInvalid returns true if err is a DEP "invalid cursor" error.

func NewHTTPError

func NewHTTPError(r *http.Response) error

NewHTTPError creates and returns a new HTTPError from r. Note this reads all of r.Body and the caller is responsible for closing it.

Types

type AccountDetail added in v0.3.0

type AccountDetail struct {
	AdminID       string `json:"admin_id"`
	FacilitatorID string `json:"facilitator_id,omitempty"`
	OrgAddress    string `json:"org_address"`
	OrgEMail      string `json:"org_email"`
	OrgID         string `json:"org_id"`
	OrgIDHash     string `json:"org_id_hash"`
	OrgName       string `json:"org_name"`
	OrgPhone      string `json:"org_phone"`
	OrgType       string `json:"org_type"`
	OrgVersion    string `json:"org_version"`
	ServerName    string `json:"server_name"`
	ServerUUID    string `json:"server_uuid"`
	URLs          []URL  `json:"urls"`
}

AccountDetail corresponds to the Apple DEP API "AccountDetail" structure. See https://developer.apple.com/documentation/devicemanagement/accountdetail

type ClearProfileResponse added in v0.2.0

type ClearProfileResponse struct {
	Devices map[string]string `json:"devices"`
}

ClearProfileResponse corresponds to the Apple DEP API "ClearProfileResponse" structure. See https://developer.apple.com/documentation/devicemanagement/clearprofileresponse

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client represents an Apple DEP API client identified by a single DEP name.

func NewClient

func NewClient(store ClientStorage, opts ...Option) *Client

NewClient creates new Client and reads authentication and config data from store.

func (*Client) AccountDetail added in v0.3.0

func (c *Client) AccountDetail(ctx context.Context, name string) (*AccountDetail, error)

AccountDetail uses the Apple "Obtain the details for your account" API endpoint to get the details about the DEP account and MDM server. See https://developer.apple.com/documentation/devicemanagement/get_account_detail

func (*Client) AssignProfile

func (c *Client) AssignProfile(ctx context.Context, name, uuid string, serials ...string) (*ProfileResponse, error)

AssignProfiles uses the Apple "Assign a profile to a list of devices" API endpoint to assign a DEP profile UUID to a list of serial numbers. The name parameter specifies the configured DEP name to use. Note we use HTTP PUT for compatibility despite modern documentation listing HTTP POST for this endpoint. See https://developer.apple.com/documentation/devicemanagement/assign_a_profile

func (*Client) DefineProfile added in v0.2.0

func (c *Client) DefineProfile(ctx context.Context, name string, profile *Profile) (*ProfileResponse, error)

DefineProfile uses the Apple "Define a Profile" command to attempt to create a profile. This service defines a profile with Apple's servers that can then be assigned to specific devices. This command provides information about the MDM server that is assigned to manage one or more devices, information about the host that the managed devices can pair with, and various attributes that control the MDM association behavior of the device. See https://developer.apple.com/documentation/devicemanagement/define_a_profile

func (*Client) DeviceDetails added in v0.2.0

func (c *Client) DeviceDetails(ctx context.Context, name string, serials ...string) (*DeviceListResponse, error)

DeviceDetails uses the Apple "Get Device Details" API endpoint to get the details on a set of devices. See https://developer.apple.com/documentation/devicemanagement/get_device_details

func (*Client) DisownDevices added in v0.4.0

func (c *Client) DisownDevices(ctx context.Context, name string, serials ...string) (*DeviceStatusResponse, error)

DisownDevices uses the Apple "Disown Devices" API endpoint to disclaim ownership of device serial numbers. WARNING: This will permanantly remove devices from the ABM/ASM/ABE instance. Use with caution. See https://developer.apple.com/documentation/devicemanagement/disown_devices

func (*Client) FetchDevices

func (c *Client) FetchDevices(ctx context.Context, name string, opts ...DeviceRequestOption) (*DeviceResponse, error)

FetchDevices uses the Apple "Get a List of Devices" API endpoint to retrieve a list of all devices corresponding to this configured DEP server (DEP name). The name parameter specifies the configured DEP name to use. You should provide a cursor that is returned from previous FetchDevices call responses on any subsequent calls. See https://developer.apple.com/documentation/devicemanagement/get_a_list_of_devices

func (*Client) GetProfile added in v0.2.1

func (c *Client) GetProfile(ctx context.Context, name, uuid string) (*Profile, error)

GetProfile uses the Apple "Get a Profile" API endpoint to return the DEP profile named by the given UUID. See https://developer.apple.com/documentation/devicemanagement/get_a_profile

func (*Client) RemoveProfile added in v0.2.0

func (c *Client) RemoveProfile(ctx context.Context, name string, serials ...string) (*ClearProfileResponse, error)

RemoveProfile uses the Apple "Remove a Profile" API endpoint to "unassign" any DEP profile UUID from a list of serial numbers. A `profile_uuid` API paramater is listed in the documentation but we do not support it (nor does it appear to be used on the server-side). The name parameter specifies the configured DEP name to use. See https://developer.apple.com/documentation/devicemanagement/remove_a_profile-c2c

func (*Client) SyncDevices

func (c *Client) SyncDevices(ctx context.Context, name string, opts ...DeviceRequestOption) (*DeviceResponse, error)

SyncDevices uses the Apple "Sync the List of Devices" API endpoint to get updates about the list of devices corresponding to this configured DEP server (DEP name). The name parameter specifies the configured DEP name to use. You should provide a cursor that is returned from previous FetchDevices or SyncDevices call responses. See https://developer.apple.com/documentation/devicemanagement/sync_the_list_of_devices

type ClientStorage

type ClientStorage interface {
	depclient.AuthTokensRetriever
	depclient.ConfigRetriever
}

ClientStorage provides the required data needed to connect to the Apple DEP APIs.

type Device

type Device struct {
	SerialNumber       string    `json:"serial_number"`
	Model              string    `json:"model"`
	Description        string    `json:"description"`
	Color              string    `json:"color"`
	AssetTag           string    `json:"asset_tag,omitempty"`
	ProfileStatus      string    `json:"profile_status"`
	ProfileUUID        string    `json:"profile_uuid,omitempty"`
	ProfileAssignTime  time.Time `json:"profile_assign_time,omitempty"`
	ProfilePushTime    time.Time `json:"profile_push_time,omitempty"`
	DeviceAssignedDate time.Time `json:"device_assigned_date,omitempty"`
	DeviceAssignedBy   string    `json:"device_assigned_by,omitempty"`
	OS                 string    `json:"os,omitempty"`
	DeviceFamily       string    `json:"device_family,omitempty"`

	// OpType and OpDate are only populated from the sync endpoint
	OpType string    `json:"op_type,omitempty"`
	OpDate time.Time `json:"op_date,omitempty"`

	// ResponseStatus is only populated from the details endpoint
	ResponseStatus string `json:"response_status,omitempty"`
}

Device corresponds to the Apple DEP API "Device" structure. See https://developer.apple.com/documentation/devicemanagement/device

type DeviceListRequest added in v0.4.0

type DeviceListRequest struct {
	Devices []string `json:"devices"`
}

DeviceListRequest corresponds to the Apple API "DeviceListRequest" structure. See https://developer.apple.com/documentation/devicemanagement/devicelistrequest

type DeviceListResponse added in v0.2.0

type DeviceListResponse struct {
	Devices map[string]Device `json:"devices"`
}

DeviceListResponse corresponds to the Apple API "DeviceListResponse" structure. See https://developer.apple.com/documentation/devicemanagement/devicelistresponse

type DeviceRequestOption

type DeviceRequestOption func(*deviceRequest)

func WithCursor

func WithCursor(cursor string) DeviceRequestOption

WithCursor includes a cursor in the fetch or sync request. The initial fetch request should omit this option.

func WithLimit

func WithLimit(limit int) DeviceRequestOption

WithCursor includes a device limit in the fetch or sync request. Per Apple the API has a default of 100 and a maximum of 1000.

type DeviceResponse

type DeviceResponse struct {
	Cursor       string    `json:"cursor,omitempty"`
	FetchedUntil time.Time `json:"fetched_until,omitempty"`
	MoreToFollow bool      `json:"more_to_follow"`
	Devices      []Device  `json:"devices,omitempty"`
}

DeviceResponse corresponds to the Apple DEP "FetchDeviceResponse" structure. See https://developer.apple.com/documentation/devicemanagement/fetchdeviceresponse

type DeviceStatusResponse added in v0.4.0

type DeviceStatusResponse struct {
	Devices map[string]string `json:"devices"`
}

DeviceStatusResponse corresponds to the Apple API "DeviceStatusRepoonse" structure. See https://developer.apple.com/documentation/devicemanagement/devicestatusresponse

type HTTPError

type HTTPError struct {
	Body       []byte
	Status     string
	StatusCode int
}

HTTPError encapsulates an HTTP response error from the DEP requests. The API returns error information in the request body.

func (*HTTPError) Error

func (e *HTTPError) Error() string

type Limit added in v0.3.0

type Limit struct {
	Default int `json:"default"`
	Maximum int `json:"maximum"`
}

Limit corresponds to the Apple DEP API "Limit" structure. See https://developer.apple.com/documentation/devicemanagement/limit

type Option added in v0.4.0

type Option func(*Client)

Options change the configuration of the godep Client.

func WithClient added in v0.4.0

func WithClient(client *http.Client) Option

WithClient configures the HTTP client to be used. The provided client is copied and modified by wrapping its transport in a new NanoDEP transport (which transparently handles authentication and session management). If not set then http.DefaultClient is used.

func WithUserAgent added in v0.4.0

func WithUserAgent(ua string) Option

WithUserAgent sets the the HTTP User-Agent string to be used on each request.

type Profile added in v0.2.0

type Profile struct {
	ProfileName           string   `json:"profile_name"`
	URL                   string   `json:"url"`
	AllowPairing          bool     `json:"allow_pairing,omitempty"`
	IsSupervised          bool     `json:"is_supervised,omitempty"`
	IsMultiUser           bool     `json:"is_multi_user,omitempty"`
	IsMandatory           bool     `json:"is_mandatory,omitempty"`
	AwaitDeviceConfigured bool     `json:"await_device_configured,omitempty"`
	IsMDMRemovable        bool     `json:"is_mdm_removable"` // default true
	SupportPhoneNumber    string   `json:"support_phone_number,omitempty"`
	AutoAdvanceSetup      bool     `json:"auto_advance_setup,omitempty"`
	SupportEmailAddress   string   `json:"support_email_address,omitempty"`
	OrgMagic              string   `json:"org_magic"`
	AnchorCerts           []string `json:"anchor_certs,omitempty"`
	SupervisingHostCerts  []string `json:"supervising_host_certs,omitempty"`
	Department            string   `json:"department,omitempty"`
	Devices               []string `json:"devices,omitempty"`
	Language              string   `json:"language,omitempty"`
	Region                string   `json:"region,omitempty"`
	ConfigurationWebURL   string   `json:"configuration_web_url,omitempty"`

	// See https://developer.apple.com/documentation/devicemanagement/skipkeys
	SkipSetupItems []string `json:"skip_setup_items,omitempty"`

	// additional undocumented key only returned when requesting a profile from Apple.
	ProfileUUID string `json:"profile_uuid,omitempty"`
}

Profile corresponds to the Apple DEP API "Profile" structure. See https://developer.apple.com/documentation/devicemanagement/profile

type ProfileResponse

type ProfileResponse struct {
	ProfileUUID string            `json:"profile_uuid"`
	Devices     map[string]string `json:"devices"`
}

ProfileResponse corresponds to the Apple DEP API "AssignProfileResponse" structure. See https://developer.apple.com/documentation/devicemanagement/assignprofileresponse Note that the "DefineProfileResponse" structure documents an array of devices when the service itself returns a map/dictionary/hash. See https://developer.apple.com/documentation/devicemanagement/defineprofileresponse

type URL added in v0.3.0

type URL struct {
	HTTPMethod []string `json:"http_method"`
	Limit      Limit    `json:"limit"`
	URI        string   `json:"uri"`
}

URL corresponds to the Apple DEP API "Url" structure. See https://developer.apple.com/documentation/devicemanagement/url

Jump to

Keyboard shortcuts

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