-
Notifications
You must be signed in to change notification settings - Fork 30
/
app.go
133 lines (112 loc) · 4.21 KB
/
app.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package stream_chat //nolint: golint
import (
"net/http"
"time"
)
type AppSettings struct {
DisableAuth *bool `json:"disable_auth_checks,omitempty"`
DisablePermissions *bool `json:"disable_permissions_checks,omitempty"`
APNConfig *APNConfig `json:"apn_config,omitempty"`
FirebaseConfig *FirebaseConfig `json:"firebase_config,omitempty"`
WebhookURL *string `json:"webhook_url,omitempty"`
MultiTenantEnabled *bool `json:"multi_tenant_enabled,omitempty"`
}
func (a *AppSettings) SetDisableAuth(b bool) *AppSettings {
a.DisableAuth = &b
return a
}
func (a *AppSettings) SetDisablePermissions(b bool) *AppSettings {
a.DisablePermissions = &b
return a
}
func (a *AppSettings) SetAPNConfig(c APNConfig) *AppSettings {
a.APNConfig = &c
return a
}
func (a *AppSettings) SetFirebaseConfig(c FirebaseConfig) *AppSettings {
a.FirebaseConfig = &c
return a
}
func (a *AppSettings) SetWebhookURL(s string) *AppSettings {
a.WebhookURL = &s
return a
}
func (a *AppSettings) SetMultiTenant(b bool) *AppSettings {
a.MultiTenantEnabled = &b
return a
}
func NewAppSettings() *AppSettings {
return &AppSettings{}
}
type APNConfig struct {
Enabled bool `json:"enabled"`
Development bool `json:"development"`
AuthType string `json:"auth_type,omitempty"`
AuthKey []byte `json:"auth_key,omitempty"`
NotificationTemplate string `json:"notification_template"`
Host string `json:"host,omitempty"`
BundleID string `json:"bundle_id,omitempty"`
TeamID string `json:"team_id,omitempty"`
KeyID string `json:"key_id,omitempty"`
}
type FirebaseConfig struct {
Enabled bool `json:"enabled"`
NotificationTemplate string `json:"notification_template"`
}
type PushNotificationFields struct {
APNConfig APNConfig `json:"apn"`
FirebaseConfig FirebaseConfig `json:"firebase"`
}
type Policy struct {
Name string `json:"name"`
Resources []string `json:"resources"`
Roles []string `json:"roles"`
Action int `json:"action"` // allow: 1, deny: 0
Owner bool `json:"owner"`
Priority int `json:"priority"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
}
type AppConfig struct {
Name string `json:"name"`
OrganizationName string `json:"organization"`
WebhookURL string `json:"webhook_url"`
SuspendedExplanation string `json:"suspended_explanation"`
PushNotifications PushNotificationFields `json:"push_notifications"`
ConfigNameMap map[string]*ChannelConfig `json:"channel_configs"`
Policies map[string][]Policy `json:"policies"`
Suspended bool `json:"suspended"`
DisableAuth bool `json:"disable_auth_checks"`
DisablePermissions bool `json:"disable_permissions_checks"`
MultiTenantEnabled bool `json:"multi_tenant_enabled"`
RevokeTokensIssuedBefore *time.Time `json:"revoke_tokens_issued_before"`
}
type appResponse struct {
App *AppConfig `json:"app"`
}
// GetAppConfig returns app settings.
func (c *Client) GetAppConfig() (*AppConfig, error) {
var resp appResponse
err := c.makeRequest(http.MethodGet, "app", nil, nil, &resp)
if err != nil {
return nil, err
}
return resp.App, nil
}
// UpdateAppSettings makes request to update app settings
// Example of usage:
// settings := NewAppSettings().SetDisableAuth(true)
// err := client.UpdateAppSettings(settings)
func (c *Client) UpdateAppSettings(settings *AppSettings) error {
return c.makeRequest(http.MethodPatch, "app", nil, settings, nil)
}
// RevokeTokens revokes all tokens for an application issued before given time.
func (c *Client) RevokeTokens(before *time.Time) error {
setting := make(map[string]interface{})
if before == nil {
setting["revoke_tokens_issued_before"] = nil
} else {
setting["revoke_tokens_issued_before"] = before.Format(time.RFC3339)
}
return c.makeRequest(http.MethodPatch, "app", nil, setting, nil)
}