-
Notifications
You must be signed in to change notification settings - Fork 11
/
client.go
51 lines (40 loc) · 1.08 KB
/
client.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//
// Copyright (c) 2020 SSH Communications Security Inc.
//
// All rights reserved.
//
package config
import (
"github.com/SSHcom/privx-sdk-go/restapi"
)
// ConfFileStore is a role-store client instance.
type ConfFileStore struct {
api restapi.Connector
}
type tSession struct {
ID string `json:"session_id"`
}
// New creates a new client instance to fetch config files from PrivX
func New(api restapi.Connector) *ConfFileStore {
return &ConfFileStore{api: api}
}
// ConfigExtender fetches configuration file
func (store *ConfFileStore) ConfigExtender(id string) ([]byte, error) {
return store.config("extender/conf", id)
}
// ConfigDeploy fetches deployment script
func (store *ConfFileStore) ConfigDeploy(id string) ([]byte, error) {
return store.config("deploy", id)
}
func (store *ConfFileStore) config(config, id string) ([]byte, error) {
var session tSession
_, err := store.api.
URL("/authorizer/api/v1/%s/%s", config, id).
Post("", &session)
if err != nil {
return nil, err
}
return store.api.
URL("/authorizer/api/v1/%s/%s/%s", config, id, session.ID).
Fetch()
}