Skip to content

Commit

Permalink
Endpoint for getting profiles added (#201)
Browse files Browse the repository at this point in the history
* few simple changes to restapi readme

* function GetProfiles is added

* return statements are added now
  • Loading branch information
ash-kamrip authored Nov 13, 2022
1 parent 0200143 commit 37ed34d
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 5 deletions.
9 changes: 5 additions & 4 deletions restapi/README.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
# 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

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
Expand Down
32 changes: 32 additions & 0 deletions restapi/api/device_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
//========================================
Expand Down
1 change: 1 addition & 0 deletions restapi/api/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion restapi/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand Down
2 changes: 2 additions & 0 deletions restapi/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down

0 comments on commit 37ed34d

Please sign in to comment.