Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
cozy_oauth_proxy
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
web-et-numerique
Factory
LLLE_Project
cozy_oauth_proxy
Commits
4303069f
Commit
4303069f
authored
4 years ago
by
Hugo NOUTS
Browse files
Options
Downloads
Patches
Plain Diff
parse enedis code containing status code when error
strconv.Atoi string code into int status code
parent
8d744da4
No related branches found
No related tags found
No related merge requests found
Pipeline
#7366
failed
4 years ago
Stage: build
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
main.go
+36
-12
36 additions, 12 deletions
main.go
with
36 additions
and
12 deletions
main.go
+
36
−
12
View file @
4303069f
...
...
@@ -50,6 +50,20 @@ func LookupEnvOrInt(key string, defaultVal int) int {
return
defaultVal
}
func
findItem
(
arrayType
interface
{},
item
interface
{})
bool
{
arr
:=
reflect
.
ValueOf
(
arrayType
)
if
arr
.
Kind
()
!=
reflect
.
Array
{
panic
(
"Invalid data-type"
)
}
for
i
:=
0
;
i
<
arr
.
Len
();
i
++
{
if
arr
.
Index
(
i
)
.
Interface
()
==
item
{
return
true
}
}
return
false
}
func
main
()
{
// Parse the flags
flag
.
Parse
()
...
...
@@ -127,21 +141,31 @@ func main() {
code
:=
query
.
Get
(
"code"
)
req_state
:=
query
.
Get
(
"state"
)
statusCodes
:=
[
4
]
string
{
"400"
,
"403"
,
"500"
,
"503"
}
splitIndex
:=
strings
.
Index
(
req_state
,
"-"
)
if
splitIndex
==
-
1
{
log
.
Warning
(
"No host found"
)
}
state
:=
req_state
[
0
:
splitIndex
]
host
:=
req_state
[
splitIndex
+
1
:
]
if
(
findItem
(
statusCodes
,
code
))
{
intCode
,
err
:=
strconv
.
Atoi
(
code
)
if
err
!=
nil
{
log
.
Print
(
"status code string to int error: "
,
err
)
}
log
.
Print
(
"status code error : "
,
code
)
http
.
Error
(
w
,
http
.
StatusText
(
intCode
),
intCode
)
}
else
{
splitIndex
:=
strings
.
Index
(
req_state
,
"-"
)
if
splitIndex
==
-
1
{
log
.
Warning
(
"No host found"
)
}
state
:=
req_state
[
0
:
splitIndex
]
host
:=
req_state
[
splitIndex
+
1
:
]
usagePointId
:=
query
.
Get
(
"usage_point_id"
)
usagePointId
:=
query
.
Get
(
"usage_point_id"
)
cozyURL
:=
"https://"
+
host
+
"."
+
*
cozyDomain
+
*
cozyRedirectURI
cozyURL
:=
"https://"
+
host
+
"."
+
*
cozyDomain
+
*
cozyRedirectURI
redir
:=
cozyURL
+
"?code="
+
code
+
"&state="
+
state
+
"&usage_point_id="
+
usagePointId
log
.
Debug
(
"Redirect to -"
,
redir
)
http
.
Redirect
(
w
,
r
,
redir
,
302
)
redir
:=
cozyURL
+
"?code="
+
code
+
"&state="
+
state
+
"&usage_point_id="
+
usagePointId
log
.
Debug
(
"Redirect to -"
,
redir
)
http
.
Redirect
(
w
,
r
,
redir
,
302
)
}
})
mux
.
HandleFunc
(
"/token"
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
...
...
@@ -241,7 +265,7 @@ func main() {
data
.
Set
(
"grant_type"
,
"refresh_token"
)
}
log
.
Debug
(
"Send request to token endpoint"
,
tokenUrl
)
log
.
Debug
(
"Send request to token endpoint
:
"
,
tokenUrl
)
response
,
err
:=
http
.
PostForm
(
tokenUrl
,
data
)
if
err
!=
nil
{
log
.
Error
(
err
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment