Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
circe-helper
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
certic
circe-helper
Commits
490dfad5
Commit
490dfad5
authored
4 years ago
by
Mickaël Desfrênes
Browse files
Options
Downloads
Patches
Plain Diff
Slightly better error handling. README edited.
parent
2ae79dcb
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
README.md
+35
-0
35 additions, 0 deletions
README.md
circe.go
+38
-15
38 additions, 15 deletions
circe.go
with
73 additions
and
15 deletions
README.md
+
35
−
0
View file @
490dfad5
# circe-helper
## Build
Development build for your current platform:
go build circe.go
Release build For windows:
GOOS=windows GOARCH=amd64 go build -ldflags "-s -w" circe.go
Release build for MacOS:
GOOS=darwin GOARCH=amd64 go build -ldflags "-s -w" circe.go
Release build for Linux:
GOOS=linux GOARCH=amd64 go build -ldflags "-s -w" circe.go
(Optional) Binary compression, if UPX is available:
upx circe
## Usage
./circe [optional flags] source_file transformation_name destination_file
Example:
./circe test1.html html2pdf test1.pdf
Optional flags:
-endpoint=[circe service endpoint] # will default to env var CIRCE_ENDPOINT
-appuuid=[your application UUID] # will default to env var CIRCE_APP_UUID
-secret=[your application secret] # will default to env var CIRCE_SECRET
\ No newline at end of file
This diff is collapsed.
Click to expand it.
circe.go
+
38
−
15
View file @
490dfad5
...
...
@@ -9,6 +9,7 @@ import (
"encoding/hex"
"encoding/json"
"errors"
"flag"
"fmt"
"io"
"io/ioutil"
...
...
@@ -210,13 +211,18 @@ func (client CirceClient) SendJob(job *Job) error {
httpClient
:=
&
http
.
Client
{}
postRequest
,
err
:=
http
.
NewRequest
(
"POST"
,
client
.
Endpoint
+
"job/"
,
archiveFilePointer
)
checkerr
(
err
)
if
err
!=
nil
{
return
err
}
postRequest
.
Header
.
Add
(
"Authorization"
,
client
.
ApplicationUuid
+
" "
+
hmacDigest
)
response
,
err
:=
httpClient
.
Do
(
postRequest
)
if
err
!=
nil
{
return
err
}
defer
response
.
Body
.
Close
()
if
response
.
StatusCode
!=
200
{
return
errors
.
New
(
fmt
.
Sprintf
(
"Response status error: %v"
,
response
.
StatusCode
))
}
jobUuid
,
_
:=
ioutil
.
ReadAll
(
response
.
Body
)
job
.
Uuid
=
string
(
jobUuid
)
defer
os
.
Remove
(
archiveFilePointer
.
Name
())
...
...
@@ -268,15 +274,21 @@ func (client CirceClient) Poll(job *Job, destinationFilePath string, timeout int
}
func
showHelpAndExit
()
{
message
:=
`
-=
Command-line client to the Circe API
=-
message
:=
`Command-line client to the Circe API
Usage:
%s [source
file
] [
transformation
] [
destination
file
]
%s [
optional flags]
source
_
file
transformation
_name
destination
_
file
Example:
%s test1.html html2pdf test1.pdf
Optional flags:
-endpoint=[circe service endpoint]
-appuuid=[your application UUID]
-secret=[your application secret]
`
fmt
.
Printf
(
message
,
os
.
Args
[
0
],
os
.
Args
[
0
])
os
.
Exit
(
0
)
...
...
@@ -290,16 +302,20 @@ func getEnv(key, fallback string) string {
}
func
main
()
{
circeEndpoint
:=
getEnv
(
"CIRCE_ENDPOINT"
,
"https://circe.bontards.com/"
)
circeSecret
:=
getEnv
(
"CIRCE_SECRET"
,
"@Jy_<b)Fy%/TkVlJ=T#kZIyFt3E_?B.T"
)
circeAppUuid
:=
getEnv
(
"CIRCE_APP_UUID"
,
"7f5a3ce0-a729-4e41-80df-cad73aee96b2"
)
/*
if circeEndpoint == "" || circeAppUuid == "" || circeSecret == "" {
log.Fatalln("Please set the following environment variables: CIRCE_ENDPOINT, CIRCE_SECRET, CIRCE_APP_UUID")
}
*/
args
:=
os
.
Args
[
1
:
]
if
len
(
args
)
<
3
{
var
circeEndpoint
string
var
circeSecret
string
var
circeAppUuid
string
var
seeHelp
bool
flag
.
BoolVar
(
&
seeHelp
,
"h"
,
false
,
"Show help and exit"
)
flag
.
BoolVar
(
&
seeHelp
,
"help"
,
false
,
"Show help and exit"
)
flag
.
StringVar
(
&
circeEndpoint
,
"endpoint"
,
getEnv
(
"CIRCE_ENDPOINT"
,
"https://circe.bontards.com/"
),
"Service Endpoint"
)
flag
.
StringVar
(
&
circeSecret
,
"secret"
,
getEnv
(
"CIRCE_SECRET"
,
"@Jy_<b)Fy%/TkVlJ=T#kZIyFt3E_?B.T"
),
"Secret Key"
)
flag
.
StringVar
(
&
circeAppUuid
,
"appuuid"
,
getEnv
(
"CIRCE_APP_UUID"
,
"7f5a3ce0-a729-4e41-80df-cad73aee96b2"
),
"Application UUID"
)
flag
.
Parse
()
args
:=
flag
.
Args
()
if
len
(
args
)
<
3
||
seeHelp
{
showHelpAndExit
()
}
...
...
@@ -320,11 +336,18 @@ func main() {
}
tmpTgzFile
,
err
:=
ioutil
.
TempFile
(
os
.
TempDir
(),
"*.tar.gz"
)
checkerr
(
err
)
if
err
!=
nil
{
log
.
Fatal
(
"Could not create temporary tar"
)
}
defer
os
.
Remove
(
tmpTgzFile
.
Name
())
_
,
err
=
circe
.
Poll
(
&
job
,
tmpTgzFile
.
Name
(),
30
)
checkerr
(
err
)
if
err
!=
nil
{
log
.
Println
(
"Could not complete document conversion. Reason:"
)
log
.
Fatal
(
err
)
}
ExtractTarGz
(
tmpTgzFile
,
destination
)
}
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