-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
executable file
·174 lines (137 loc) · 4.02 KB
/
main.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
/*
* Copyright (c) 2016 General Electric Company. All rights reserved.
*
* The copyright to the computer software herein is the property of
* General Electric Company. The software may be used and/or copied only
* with the written permission of General Electric Company or in accordance
* with the terms and conditions stipulated in the agreement/contract
* under which the software has been supplied.
*
* author: apolo.yasuda@ge.com
*/
package main
import (
"os"
"flag"
"errors"
//"net"
"net/url"
util "github.com/wzlib/wzutil"
plugin "github.com/wzlib/wzplugin"
model "github.com/wzlib/wzschema"
"gopkg.in/yaml.v2"
"encoding/base64"
)
var (
REV string = "beta"
)
const (
EC_LOGO = `
▄▄▄▄▄▄▄▄▄▄▄ ▄▄▄▄▄▄▄▄▄▄▄
▐░░░░░░░░░░░▌▐░░░░░░░░░░░
▐░█▀▀▀▀▀▀▀▀▀ ▐░█▀▀▀▀▀▀▀▀▀
▐░▌ ▐░▌
▐░█▄▄▄▄▄▄▄▄▄ ▐░▌
▐░░░░░░░░░░░▌▐░▌
▐░█▀▀▀▀▀▀▀▀▀ ▐░▌
▐░▌ ▐░▌
▐░█▄▄▄▄▄▄▄▄▄ ▐░█▄▄▄▄▄▄▄▄▄
▐░░░░░░░░░░░▌▐░░░░░░░░░░░▌
▀▀▀▀▀▀▀▀▀▀▀ ▀▀▀▀▀▀▀▀▀▀▀ @Enterprise-Connect
`
COPY_RIGHT = "Enterprise-Connect, @General Electric"
ISSUE_TRACKER = "https://github.com/EC-Release/sdk/issues"
//agent authorization header
AUTH_HEADER = "Authorization"
//ec service header in predix
EC_SUB_HEADER = "Predix-Zone-Id"
//app index available in a cf environment
CF_INS_IDX_EV = "CF_INSTANCE_INDEX"
//forwarding header targeting a cf environment
CF_INS_HEADER = "X-CF-APP-INSTANCE"
//app index available in a watcher environment
EC_INS_IDX_EV = "EC_INSTANCE_INDEX"
//forwarding header targeting a watcher environement
EC_INS_HEADER = "X-EC-APP-INSTANCE"
//deprecated
//xcalr url
CA_URL = "https://xcalr.apps.ge.com/v2beta"
//deprecated
//watcher url
WATCHER_URL = "https://raw.githubusercontent.com/Enterprise-connect/sdk/v1.1beta.watcher/watcher.yml"
)
func GetTLSSetting()(map[string]interface{}, error){
plg:=flag.String("plg","","Enable support for EC TLS Plugin.")
ver:=flag.Bool("ver", false, "Show current tls revision.")
flag.Parse()
if *ver {
util.InfoLog("Rev:"+REV)
os.Exit(0)
return nil,nil
}
//util.DbgLog(*plg)
f, err := base64.StdEncoding.DecodeString(*plg)
if err!=nil{
return nil, err
}
t:=make(map[string]interface{})
err=yaml.Unmarshal(f, &t)
if err!=nil{
return nil,err
}
if len(t)<1 {
return nil, errors.New("invalid file format in plugins.yml")
}
return t,nil
}
func init(){
}
func main(){
defer func(){
if r:=recover();r!=nil{
util.PanicRecovery(r)
} else {
util.InfoLog("plugin undeployed.")
}
}()
bc:=&model.BrandingConfig{
CONFIG_MAIN: "/.ec",
BRAND_CONFIG: "EC",
ART_NAME: "agent",
LOGO: EC_LOGO,
COPY_RIGHT: COPY_RIGHT,
HEADER_PLUGIN: "ec-plugin",
HEADER_CONFIG: "ec-config",
HEADER_AUTH: AUTH_HEADER,
HEADER_SUB_ID: EC_SUB_HEADER,
HEADER_CF_INST: CF_INS_HEADER,
HEADER_INST: EC_INS_HEADER,
ENV_CF_INST_IDX: CF_INS_IDX_EV,
ENV_INST_IDX: EC_INS_IDX_EV,
URL_CA: CA_URL,
//URL_WATCHER_CONF: WATCHER_URL,
//URL_WATCHER_REPO: WATCHER_CONTR_URL,
URL_ISSUE_TRACKER: ISSUE_TRACKER,
}
util.Branding(bc)
util.Init("tls",true)
t,err:=GetTLSSetting()
if err!=nil{
panic(err)
}
util.DbgLog(t)
//tcp resolve is irrelevant in this plugin, use http proxy instead
//_, err= net.ResolveTCPAddr("tcp",t["hostname"].(string)+":"+t["tlsport"].(string))
//if err != nil {
// panic(err)
//}
p:=plugin.NewProxy(REV)
u, err := url.Parse(t["proxy"].(string))
if err != nil {
panic(err)
}
if err:=p.Init(t["schema"].(string)+"://"+t["hostname"].(string)+":"+t["tlsport"].(string),u);err!=nil{
panic(err)
}
p.Start(t["port"].(string))
}