Skip to content

Commit d50e94b

Browse files
committed
Enroll actions in cli using the API
1 parent 0e9b7f2 commit d50e94b

File tree

6 files changed

+380
-207
lines changed

6 files changed

+380
-207
lines changed

cli/api-environment.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package main
2+
3+
import (
4+
"encoding/json"
5+
"fmt"
6+
7+
"github.com/jmpsec/osctrl/environments"
8+
)
9+
10+
// GetEnvironments to retrieve all environments from osctrl
11+
func (api *OsctrlAPI) GetEnvironments() ([]environments.TLSEnvironment, error) {
12+
var envs []environments.TLSEnvironment
13+
reqURL := fmt.Sprintf("%s%s%s", api.Configuration.URL, APIPath, APIEnvironments)
14+
rawEnvs, err := api.GetGeneric(reqURL, nil)
15+
if err != nil {
16+
return envs, fmt.Errorf("error api request - %v - %s", err, string(rawEnvs))
17+
}
18+
if err := json.Unmarshal(rawEnvs, &envs); err != nil {
19+
return envs, fmt.Errorf("can not parse body - %v", err)
20+
}
21+
return envs, nil
22+
}
23+
24+
// GetEnvironment to retrieve users from osctrl
25+
func (api *OsctrlAPI) GetEnvironment(identifier string) (environments.TLSEnvironment, error) {
26+
var e environments.TLSEnvironment
27+
reqURL := fmt.Sprintf("%s%s%s/%s", api.Configuration.URL, APIPath, APIEnvironments, identifier)
28+
rawE, err := api.GetGeneric(reqURL, nil)
29+
if err != nil {
30+
return e, fmt.Errorf("error api request - %v - %s", err, string(rawE))
31+
}
32+
if err := json.Unmarshal(rawE, &e); err != nil {
33+
return e, fmt.Errorf("can not parse body - %v", err)
34+
}
35+
return e, nil
36+
}

cli/api.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ const (
2626
APICarves = "/carves"
2727
// APIUsers for the users path
2828
APIUSers = "/users"
29+
// APIEnvironments for the environments path
30+
APIEnvironments = "/environments"
2931
// APILogin for the login path
3032
APILogin = "/login"
3133
// JSONApplication for Content-Type headers

0 commit comments

Comments
 (0)