From 37ed34d852583c1fc78a997c7692ea5b0ecce31d Mon Sep 17 00:00:00 2001 From: adhanaAshu <31374305+ash-kamrip@users.noreply.github.com> Date: Sun, 13 Nov 2022 16:53:29 +0530 Subject: [PATCH] Endpoint for getting profiles added (#201) * few simple changes to restapi readme * function GetProfiles is added * return statements are added now --- restapi/README.md | 9 +++++---- restapi/api/device_endpoints.go | 32 ++++++++++++++++++++++++++++++++ restapi/api/routes.go | 1 + restapi/go.mod | 3 ++- restapi/go.sum | 2 ++ 5 files changed, 42 insertions(+), 5 deletions(-) diff --git a/restapi/README.md b/restapi/README.md index 4c764e98..3f2179c1 100644 --- a/restapi/README.md +++ b/restapi/README.md @@ -1,6 +1,7 @@ # Go-iOS REST API ## getting started: +- Open up `restapi` folder in its own vscode window to start working on the api - go install github.com/swaggo/swag/cmd/swag@latest - swag init --parseDependency - go run main.go @@ -8,10 +9,10 @@ plug an ios device into your machine and test on localhost:8080 ## structure - - api/routes.go contains all routes - - api/middleware.go contains all middlewares - - api/*_endpoints.go contains endpoints that mostly mirror go-ios docopt commands - - api/server.go the server config + - `api/routes.go` contains all routes + - `api/middleware.go` contains all middlewares + - `api/*_endpoints.go` contains endpoints that mostly mirror go-ios docopt commands + - `api/server.go` the server config ## to dos diff --git a/restapi/api/device_endpoints.go b/restapi/api/device_endpoints.go index c81ffc10..3ecc0aca 100644 --- a/restapi/api/device_endpoints.go +++ b/restapi/api/device_endpoints.go @@ -6,6 +6,7 @@ import ( "github.com/danielpaulus/go-ios/ios" "github.com/danielpaulus/go-ios/ios/instruments" + "github.com/danielpaulus/go-ios/ios/mcinstall" "github.com/danielpaulus/go-ios/ios/screenshotr" "github.com/danielpaulus/go-ios/ios/simlocation" "github.com/gin-gonic/gin" @@ -121,6 +122,37 @@ func ResetLocation(c *gin.Context) { c.JSON(http.StatusOK, GenericResponse{Message: "Device location reset"}) } +// Get the list of installed profiles +// @Summary get the list of profiles +// @Description get the list of installed profiles from the ios device +// @Tags general_device_specific +// @Produce json +// @Success 200 {object} map[string]interface{} +// @Failure 500 {object} GenericResponse +// @Failure 404 {object} GenericResponse +// @Router /device/{udid}/profiles [get] +func GetProfiles(c *gin.Context) { + + device := c.MustGet(IOS_KEY).(ios.DeviceEntry) + + mcinstallconn, err := mcinstall.New(device) + if err != nil { + c.JSON(http.StatusInternalServerError, gin.H{"message": "Failed getting device list with error", "error": err.Error()}) + return + } + + defer mcinstallconn.Close() + + profileInfo, err := mcinstallconn.HandleList() + if err != nil { + c.JSON(http.StatusNotFound, gin.H{"message": "Failed getting profile list with error", "error": err.Error()}) + return + } + + c.JSON(http.StatusOK, profileInfo) + +} + //======================================== // DEVICE STATE CONDITIONS //======================================== diff --git a/restapi/api/routes.go b/restapi/api/routes.go index 85a9efef..3dc65489 100644 --- a/restapi/api/routes.go +++ b/restapi/api/routes.go @@ -20,6 +20,7 @@ func registerRoutes(router *gin.RouterGroup) { device.POST("/disable-condition", DisableDeviceCondition) device.POST("/reservations", ReserveDevice) + device.GET("/profiles", GetProfiles) initAppRoutes(device) initStreamingResponseRoutes(device, router) diff --git a/restapi/go.mod b/restapi/go.mod index e4044c99..0f0866ae 100644 --- a/restapi/go.mod +++ b/restapi/go.mod @@ -3,7 +3,7 @@ module github.com/danielpaulus/go-ios/restapi go 1.17 require ( - github.com/danielpaulus/go-ios v1.0.47 + github.com/danielpaulus/go-ios v1.0.91 github.com/gin-gonic/gin v1.8.1 github.com/sirupsen/logrus v1.8.1 github.com/swaggo/files v0.0.0-20220728132757-551d4a08d97a @@ -51,6 +51,7 @@ require ( require ( github.com/davecgh/go-spew v1.1.1 // indirect + github.com/pierrec/lz4 v2.6.1+incompatible // indirect github.com/pmezard/go-difflib v1.0.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/restapi/go.sum b/restapi/go.sum index 201c08db..2e281d6f 100644 --- a/restapi/go.sum +++ b/restapi/go.sum @@ -102,6 +102,8 @@ github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT9 github.com/otiai10/mint v1.3.3/go.mod h1:/yxELlJQ0ufhjUwhshSj+wFjZ78CnZ48/1wtmBH1OTc= github.com/pelletier/go-toml/v2 v2.0.1 h1:8e3L2cCQzLFi2CR4g7vGFuFxX7Jl1kKX8gW+iV0GUKU= github.com/pelletier/go-toml/v2 v2.0.1/go.mod h1:r9LEWfGN8R5k0VXJ+0BkIe7MYkRdwZOjgMj2KwnJFUo= +github.com/pierrec/lz4 v2.6.1+incompatible h1:9UY3+iC23yxF0UfGaYrGplQ+79Rg+h/q9FV9ix19jjM= +github.com/pierrec/lz4 v2.6.1+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=