This repository has been archived by the owner on Jun 17, 2022. It is now read-only.
/
main_unix.go
190 lines (172 loc) · 7.46 KB
/
main_unix.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
// Copyright 2015 Google Inc. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd
// +build linux darwin freebsd
package main
import (
"os"
"time"
"github.com/google/cloud-print-connector/lib"
"github.com/urfave/cli"
)
var unixInitFlags = []cli.Flag{
&cli.StringFlag{
Name: "log-file-name",
Usage: "Log file name, full path",
Value: lib.DefaultConfig.LogFileName,
},
&cli.IntFlag{
Name: "log-file-max-megabytes",
Usage: "Log file max size, in megabytes",
Value: int(lib.DefaultConfig.LogFileMaxMegabytes),
},
&cli.IntFlag{
Name: "log-max-files",
Usage: "Maximum log file quantity before rollover",
Value: int(lib.DefaultConfig.LogMaxFiles),
},
&cli.BoolFlag{
Name: "log-to-journal",
Usage: "Log to the systemd journal (if available) instead of to log-file-name",
},
&cli.StringFlag{
Name: "monitor-socket-filename",
Usage: "Filename of unix socket for connector-check to talk to connector",
Value: lib.DefaultConfig.MonitorSocketFilename,
},
&cli.IntFlag{
Name: "cups-max-connections",
Usage: "Max connections to CUPS server",
Value: int(lib.DefaultConfig.CUPSMaxConnections),
},
&cli.StringFlag{
Name: "cups-connect-timeout",
Usage: "CUPS timeout for opening a new connection",
Value: lib.DefaultConfig.CUPSConnectTimeout,
},
&cli.BoolFlag{
Name: "cups-job-full-username",
Usage: "Whether to use the full username (joe@example.com) in CUPS jobs",
},
&cli.BoolFlag{
Name: "cups-ignore-raw-printers",
Usage: "Whether to ignore CUPS raw printers",
DefaultText: "1",
},
&cli.BoolFlag{
Name: "cups-ignore-class-printers",
Usage: "Whether to ignore CUPS class printers",
DefaultText: "1",
},
&cli.BoolFlag{
Name: "copy-printer-info-to-display-name",
Usage: "Whether to copy the CUPS printer's printer-info attribute to the GCP printer's defaultDisplayName",
DefaultText: "1",
},
}
var unixCommands = []*cli.Command{
&cli.Command{
Name: "init",
Aliases: []string{"i"},
Usage: "Creates a config file",
Action: initConfigFile,
Flags: append(commonInitFlags, unixInitFlags...),
},
&cli.Command{
Name: "monitor",
Aliases: []string{"m"},
Usage: "Read stats from a running connector",
Action: monitorConnector,
Flags: []cli.Flag{
&cli.DurationFlag{
Name: "monitor-timeout",
Usage: "wait for a monitor response no more than this long",
Value: 10 * time.Second,
},
},
},
}
func main() {
app := cli.NewApp()
app.Name = "gcp-connector-util"
app.Usage = lib.ConnectorName + " for CUPS utility tools"
app.Version = lib.BuildDate
app.Flags = []cli.Flag{
&lib.ConfigFilenameFlag,
}
app.Commands = append(unixCommands, commonCommands...)
app.Run(os.Args)
}
// createCloudConfig creates a config object that supports cloud and (optionally) local mode.
func createCloudConfig(context *cli.Context, xmppJID, robotRefreshToken, userRefreshToken, shareScope, proxyName string, localEnable bool) *lib.Config {
return &lib.Config{
LocalPrintingEnable: localEnable,
CloudPrintingEnable: true,
XMPPJID: xmppJID,
RobotRefreshToken: robotRefreshToken,
UserRefreshToken: userRefreshToken,
ShareScope: shareScope,
ProxyName: proxyName,
FcmServerBindUrl: context.String("fcm-server-bind-url"),
XMPPServer: lib.DefaultConfig.XMPPServer,
XMPPPort: uint16(context.Int("xmpp-port")),
XMPPPingTimeout: context.String("xmpp-ping-timeout"),
XMPPPingInterval: context.String("xmpp-ping-interval"),
GCPBaseURL: context.String("gcp-base-url"),
GCPOAuthClientID: context.String("gcp-oauth-client-id"),
GCPOAuthClientSecret: context.String("gcp-oauth-client-secret"),
GCPOAuthAuthURL: context.String("gcp-oauth-auth-url"),
GCPOAuthTokenURL: context.String("gcp-oauth-token-url"),
GCPMaxConcurrentDownloads: uint(context.Int("gcp-max-concurrent-downloads")),
NativeJobQueueSize: uint(context.Int("native-job-queue-size")),
NativePrinterPollInterval: context.String("native-printer-poll-interval"),
PrefixJobIDToJobTitle: lib.PointerToBool(context.Bool("prefix-job-id-to-job-title")),
DisplayNamePrefix: context.String("display-name-prefix"),
PrinterBlacklist: lib.DefaultConfig.PrinterBlacklist,
PrinterWhitelist: lib.DefaultConfig.PrinterWhitelist,
LogLevel: context.String("log-level"),
LocalPortLow: uint16(context.Int("local-port-low")),
LocalPortHigh: uint16(context.Int("local-port-high")),
LogFileName: context.String("log-file-name"),
LogFileMaxMegabytes: uint(context.Int("log-file-max-megabytes")),
LogMaxFiles: uint(context.Int("log-max-files")),
LogToJournal: lib.PointerToBool(context.Bool("log-to-journal")),
MonitorSocketFilename: context.String("monitor-socket-filename"),
CUPSMaxConnections: uint(context.Int("cups-max-connections")),
CUPSConnectTimeout: context.String("cups-connect-timeout"),
CUPSPrinterAttributes: lib.DefaultConfig.CUPSPrinterAttributes,
CUPSJobFullUsername: lib.PointerToBool(context.Bool("cups-job-full-username")),
CUPSIgnoreRawPrinters: lib.PointerToBool(context.Bool("cups-ignore-raw-printers")),
CUPSIgnoreClassPrinters: lib.PointerToBool(context.Bool("cups-ignore-class-printers")),
CUPSCopyPrinterInfoToDisplayName: lib.PointerToBool(context.Bool("copy-printer-info-to-display-name")),
}
}
// createLocalConfig creates a config object that supports local mode.
func createLocalConfig(context *cli.Context) *lib.Config {
return &lib.Config{
LocalPrintingEnable: true,
CloudPrintingEnable: false,
NativeJobQueueSize: uint(context.Int("native-job-queue-size")),
NativePrinterPollInterval: context.String("native-printer-poll-interval"),
PrefixJobIDToJobTitle: lib.PointerToBool(context.Bool("prefix-job-id-to-job-title")),
DisplayNamePrefix: context.String("display-name-prefix"),
PrinterBlacklist: lib.DefaultConfig.PrinterBlacklist,
PrinterWhitelist: lib.DefaultConfig.PrinterWhitelist,
LogLevel: context.String("log-level"),
LocalPortLow: uint16(context.Int("local-port-low")),
LocalPortHigh: uint16(context.Int("local-port-high")),
LogFileName: context.String("log-file-name"),
LogFileMaxMegabytes: uint(context.Int("log-file-max-megabytes")),
LogMaxFiles: uint(context.Int("log-max-files")),
LogToJournal: lib.PointerToBool(context.Bool("log-to-journal")),
MonitorSocketFilename: context.String("monitor-socket-filename"),
CUPSMaxConnections: uint(context.Int("cups-max-connections")),
CUPSConnectTimeout: context.String("cups-connect-timeout"),
CUPSPrinterAttributes: lib.DefaultConfig.CUPSPrinterAttributes,
CUPSJobFullUsername: lib.PointerToBool(context.Bool("cups-job-full-username")),
CUPSIgnoreRawPrinters: lib.PointerToBool(context.Bool("cups-ignore-raw-printers")),
CUPSIgnoreClassPrinters: lib.PointerToBool(context.Bool("cups-ignore-class-printers")),
CUPSCopyPrinterInfoToDisplayName: lib.PointerToBool(context.Bool("copy-printer-info-to-display-name")),
}
}