mirror of
https://github.com/fleetdm/fleet
synced 2026-05-22 00:18:27 +00:00
<!-- Add the related story/sub-task/bug number, like Resolves #123, or remove if NA --> **Related issue:** Resolves #34389 # Checklist for submitter If some of the following don't apply, delete the relevant line. - [x] Input data is properly validated, `SELECT *` is avoided, SQL injection is prevented (using placeholders for values in statements) ## Testing - [x] Added/updated automated tests - [x] Where appropriate, [automated tests simulate multiple hosts and test for host isolation](https://github.com/fleetdm/fleet/blob/main/docs/Contributing/reference/patterns-backend.md#unit-testing) (updates to one hosts's records do not affect another) - [x] QA'd all new/changed functionality manually ## Database migrations - [x] Checked schema for all modified table for columns that will auto-update timestamps during migration. - [x] Ensured the correct collation is explicitly set for character columns (`COLLATE utf8mb4_unicode_ci`).
65 lines
2.4 KiB
Go
65 lines
2.4 KiB
Go
package android
|
|
|
|
import (
|
|
"context"
|
|
"net/http"
|
|
|
|
"google.golang.org/api/androidmanagement/v1"
|
|
)
|
|
|
|
type Service interface {
|
|
EnterpriseSignup(ctx context.Context) (*SignupDetails, error)
|
|
EnterpriseSignupCallback(ctx context.Context, signupToken string, enterpriseToken string) error
|
|
GetEnterprise(ctx context.Context) (*Enterprise, error)
|
|
DeleteEnterprise(ctx context.Context) error
|
|
EnterpriseSignupSSE(ctx context.Context) (chan string, error)
|
|
|
|
// CreateEnrollmentToken creates an enrollment token for a new Android device.
|
|
CreateEnrollmentToken(ctx context.Context, enrollSecret, idpUUID string) (*EnrollmentToken, error)
|
|
ProcessPubSubPush(ctx context.Context, token string, message *PubSubMessage) error
|
|
|
|
// UnenrollAndroidHost triggers unenrollment (work profile removal) for the given Android host ID.
|
|
UnenrollAndroidHost(ctx context.Context, hostID uint) error
|
|
|
|
EnterprisesApplications(ctx context.Context, enterpriseName, applicationID string) (*androidmanagement.Application, error)
|
|
AddAppToAndroidPolicy(ctx context.Context, enterpriseName string, applicationIDs []string, hostUUIDs map[string]string) error
|
|
EnableAppReportsOnDefaultPolicy(ctx context.Context) error
|
|
PatchDevice(ctx context.Context, policyID, deviceName string, device *androidmanagement.Device) (skip bool, apiErr error)
|
|
PatchPolicy(ctx context.Context, policyID, policyName string, policy *androidmanagement.Policy, metadata map[string]string) (skip bool, err error)
|
|
}
|
|
|
|
// /////////////////////////////////////////////
|
|
// Android API request and response structs
|
|
|
|
type DefaultResponse struct {
|
|
Err error `json:"error,omitempty"`
|
|
}
|
|
|
|
func (r DefaultResponse) Error() error { return r.Err }
|
|
|
|
// StatusCode implements the go-kit http StatusCoder interface to preserve HTTP status codes from errors
|
|
func (r DefaultResponse) StatusCode() int {
|
|
if r.Err != nil {
|
|
// Check if the error has a custom status code (like errors created with .WithStatus())
|
|
if sc, ok := r.Err.(interface{ StatusCode() int }); ok {
|
|
return sc.StatusCode()
|
|
}
|
|
}
|
|
// Default to 200 OK if no error or no custom status code
|
|
return http.StatusOK
|
|
}
|
|
|
|
type GetEnterpriseResponse struct {
|
|
EnterpriseID string `json:"android_enterprise_id"`
|
|
DefaultResponse
|
|
}
|
|
|
|
type EnterpriseSignupResponse struct {
|
|
Url string `json:"android_enterprise_signup_url"`
|
|
DefaultResponse
|
|
}
|
|
|
|
type EnrollmentTokenResponse struct {
|
|
*EnrollmentToken
|
|
DefaultResponse
|
|
}
|