Fixed app authentication when generating

This commit is contained in:
frikky
2020-05-13 08:33:31 +02:00
parent d27650d76b
commit 59c311d78d
8 changed files with 45 additions and 17 deletions
+14 -3
View File
@@ -293,8 +293,8 @@ func makePythoncode(swagger *openapi3.Swagger, name, url, method string, paramet
urlInline := "" urlInline := ""
//log.Printf("URL: %s", url) //log.Printf("URL: %s", url)
if !strings.HasPrefix(strings.ToLower(url), "http") { if !strings.HasPrefix(strings.ToLower(url), "http") {
urlParameter = ", baseurl" urlParameter = ", url"
urlInline = "{baseurl}" urlInline = "{url}"
} }
if len(parameters) > 0 { if len(parameters) > 0 {
@@ -319,6 +319,9 @@ func makePythoncode(swagger *openapi3.Swagger, name, url, method string, paramet
} }
} }
// Extra param for url if it's changeable
// Extra param for authentication scheme(s)
data := fmt.Sprintf(` async def %s(self%s%s%s%s%s): data := fmt.Sprintf(` async def %s(self%s%s%s%s%s):
headers={} headers={}
url=f"%s%s" url=f"%s%s"
@@ -354,7 +357,7 @@ func generateYaml(swagger *openapi3.Swagger, newmd5 string) (WorkflowApp, []stri
} }
api.AppVersion = "1.0.0" api.AppVersion = "1.0.0"
api.Environment = "cloud" api.Environment = "Shuffle"
api.SmallImage = "" api.SmallImage = ""
api.LargeImage = "" api.LargeImage = ""
api.Sharing = false api.Sharing = false
@@ -387,6 +390,7 @@ func generateYaml(swagger *openapi3.Swagger, newmd5 string) (WorkflowApp, []stri
api.Authentication.Parameters[0].Name = securitySchemes["BearerAuth"].Value.Name api.Authentication.Parameters[0].Name = securitySchemes["BearerAuth"].Value.Name
api.Authentication.Parameters[0].In = securitySchemes["BearerAuth"].Value.In api.Authentication.Parameters[0].In = securitySchemes["BearerAuth"].Value.In
api.Authentication.Parameters[0].Scheme = securitySchemes["BearerAuth"].Value.Scheme api.Authentication.Parameters[0].Scheme = securitySchemes["BearerAuth"].Value.Scheme
log.Printf("HANDLE BEARER AUTH")
extraParameters = append(extraParameters, WorkflowAppActionParameter{ extraParameters = append(extraParameters, WorkflowAppActionParameter{
Name: "apikey", Name: "apikey",
Description: "The apikey to use", Description: "The apikey to use",
@@ -402,6 +406,7 @@ func generateYaml(swagger *openapi3.Swagger, newmd5 string) (WorkflowApp, []stri
api.Authentication.Parameters[0].Name = securitySchemes["ApiKeyAuth"].Value.Name api.Authentication.Parameters[0].Name = securitySchemes["ApiKeyAuth"].Value.Name
api.Authentication.Parameters[0].In = securitySchemes["ApiKeyAuth"].Value.In api.Authentication.Parameters[0].In = securitySchemes["ApiKeyAuth"].Value.In
api.Authentication.Parameters[0].Scheme = securitySchemes["ApiKeyAuth"].Value.Scheme api.Authentication.Parameters[0].Scheme = securitySchemes["ApiKeyAuth"].Value.Scheme
log.Printf("HANDLE APIKEY AUTH")
extraParameters = append(extraParameters, WorkflowAppActionParameter{ extraParameters = append(extraParameters, WorkflowAppActionParameter{
Name: "apikey", Name: "apikey",
Description: "The apikey to use", Description: "The apikey to use",
@@ -437,6 +442,8 @@ func generateYaml(swagger *openapi3.Swagger, newmd5 string) (WorkflowApp, []stri
}) })
} }
} }
// Adds a link parameter if it's not already defined
if len(api.Link) == 0 { if len(api.Link) == 0 {
extraParameters = append(extraParameters, WorkflowAppActionParameter{ extraParameters = append(extraParameters, WorkflowAppActionParameter{
Name: "url", Name: "url",
@@ -454,6 +461,7 @@ func generateYaml(swagger *openapi3.Swagger, newmd5 string) (WorkflowApp, []stri
pythonFunctions := []string{} pythonFunctions := []string{}
for actualPath, path := range swagger.Paths { for actualPath, path := range swagger.Paths {
//log.Printf("%#v", path) //log.Printf("%#v", path)
//log.Printf("%#v", actualPath) //log.Printf("%#v", actualPath)
@@ -762,11 +770,14 @@ func handleGet(swagger *openapi3.Swagger, api WorkflowApp, extraParameters []Wor
action := WorkflowAppAction{ action := WorkflowAppAction{
Description: path.Get.Description, Description: path.Get.Description,
Name: fmt.Sprintf("%s %s", "Get", path.Get.Summary), Name: fmt.Sprintf("%s %s", "Get", path.Get.Summary),
Label: fmt.Sprintf(path.Get.Summary),
NodeType: "action", NodeType: "action",
Environment: api.Environment, Environment: api.Environment,
Parameters: extraParameters, Parameters: extraParameters,
} }
log.Printf("FUNCTION: %#v", action)
action.Returns.Schema.Type = "string" action.Returns.Schema.Type = "string"
baseUrl := fmt.Sprintf("%s%s", api.Link, actualPath) baseUrl := fmt.Sprintf("%s%s", api.Link, actualPath)
+1
View File
@@ -5242,6 +5242,7 @@ func validateSwagger(resp http.ResponseWriter, request *http.Request) {
resp.Write([]byte(`{"success": false}`)) resp.Write([]byte(`{"success": false}`))
} }
// Creates an app from the app builder
func verifySwagger(resp http.ResponseWriter, request *http.Request) { func verifySwagger(resp http.ResponseWriter, request *http.Request) {
cors := handleCors(resp, request) cors := handleCors(resp, request)
if cors { if cors {
+1
View File
@@ -107,6 +107,7 @@ type WorkflowAppAction struct {
Description string `json:"description" datastore:"description"` Description string `json:"description" datastore:"description"`
ID string `json:"id" datastore:"id" yaml:"id,omitempty"` ID string `json:"id" datastore:"id" yaml:"id,omitempty"`
Name string `json:"name" datastore:"name"` Name string `json:"name" datastore:"name"`
Label string `json:"label" datastore:"label"`
NodeType string `json:"node_type" datastore:"node_type"` NodeType string `json:"node_type" datastore:"node_type"`
Environment string `json:"environment" datastore:"environment"` Environment string `json:"environment" datastore:"environment"`
Sharing bool `json:"sharing" datastore:"sharing"` Sharing bool `json:"sharing" datastore:"sharing"`
+19 -7
View File
@@ -1859,8 +1859,18 @@ const AngularWorkflow = (props) => {
{filteredApps.map(app=> { {filteredApps.map(app=> {
// FIXME - add label to apps, as this might be slow with A LOT of apps // FIXME - add label to apps, as this might be slow with A LOT of apps
var newAppname = app.name var newAppname = app.name
newAppname = newAppname.replace("_", " ") newAppname = newAppname.replace("_", " ").charAt(0).toUpperCase()+newAppname.substring(1)
newAppname = newAppname.charAt(0).toUpperCase()+newAppname.substring(1) const maxlen = 24
if (newAppname.length > maxlen) {
newAppname = newAppname.slice(0, maxlen)+".."
}
// Description fucks this up - fix overflow :)
//const maxdesclen = 5
//var desc = app.description
//if (newAppname.length > maxdesclen) {
// desc = desc.slice(0, maxdesclen)+".."
//}
const image = "url("+app.large_image+")" const image = "url("+app.large_image+")"
return( return(
@@ -1881,13 +1891,13 @@ const AngularWorkflow = (props) => {
<div style={{height: 80, width: 80, backgroundImage: image, backgroundSize: "cover", backgroundRepeat: "no-repeat"}} /> <div style={{height: 80, width: 80, backgroundImage: image, backgroundSize: "cover", backgroundRepeat: "no-repeat"}} />
</Grid> </Grid>
<Grid style={{display: "flex", flexDirection: "column", marginLeft: "20px"}}> <Grid style={{display: "flex", flexDirection: "column", marginLeft: "20px"}}>
<Grid item style={{flex: "1"}}> <Grid item style={{flex: 1}}>
<h4 style={{marginBottom: "0px", marginTop: "5px"}}>{newAppname}</h4> <h4 style={{marginBottom: "0px", marginTop: "5px"}}>{newAppname}</h4>
</Grid> </Grid>
<Grid item style={{flex: "1"}}> <Grid item style={{flex: 1, width: "100%", }}>
Description Short description...
</Grid> </Grid>
<Grid item style={{flex: "1"}}> <Grid item style={{flex: 1}}>
Version: {app.app_version} Version: {app.app_version}
</Grid> </Grid>
</Grid> </Grid>
@@ -4303,6 +4313,7 @@ const AngularWorkflow = (props) => {
fullWidth fullWidth
type="text" type="text"
color="primary" color="primary"
disabled={true}
placeholder="Bearer token" placeholder="Bearer token"
defaultValue={selectedApp.link} defaultValue={selectedApp.link}
onChange={(event) => { onChange={(event) => {
@@ -4318,6 +4329,7 @@ const AngularWorkflow = (props) => {
) )
} }
// This whole part is redundant. Made it part of Arguments instead.
const authenticationModal = authenticationModalOpen ? const authenticationModal = authenticationModalOpen ?
<Dialog modal <Dialog modal
open={authenticationModalOpen} open={authenticationModalOpen}
@@ -4337,7 +4349,7 @@ const AngularWorkflow = (props) => {
<DialogContent> <DialogContent>
<a href="/docs/apps#authentication" style={{textDecoration: "none", color: "#f85a3e"}}>What is this?</a> <a href="/docs/apps#authentication" style={{textDecoration: "none", color: "#f85a3e"}}>What is this?</a>
<div /> <div />
<EndpointData /> {selectedApp.link.length > 0 ? <EndpointData /> : null}
<div style={{marginTop: 15, marginBottom: 15, }}/> <div style={{marginTop: 15, marginBottom: 15, }}/>
<AuthenticationData /> <AuthenticationData />
</DialogContent> </DialogContent>
+3 -3
View File
@@ -1148,8 +1148,8 @@ const AppCreator = (props) => {
</div> </div>
</div> </div>
<Divider style={{marginBottom: "10px", marginTop: "30px", height: "1px", width: "100%", backgroundColor: "grey"}}/> <Divider style={{marginBottom: "10px", marginTop: "30px", height: "1px", width: "100%", backgroundColor: "grey"}}/>
<h4 style={{marginBottom: "10px"}}>General API information</h4> <h3 style={{marginBottom: "10px"}}>API information</h3>
Base URL Base URL - leave empty if user changeable
<TextField <TextField
color="primary" color="primary"
style={{backgroundColor: inputColor, marginTop: "5px"}} style={{backgroundColor: inputColor, marginTop: "5px"}}
@@ -1170,7 +1170,7 @@ const AppCreator = (props) => {
margin="normal" margin="normal"
variant="outlined" variant="outlined"
value={baseUrl} value={baseUrl}
helperText={<div style={{color:"white", marginBottom: "2px",}}>Must start with http(s):// and CANT end with /. Can be empty if you its a variable.</div>} helperText={<div style={{color:"white", marginBottom: "2px",}}>Must start with http(s):// and CANT end with /. </div>}
placeholder="https://api.example.com" placeholder="https://api.example.com"
onChange={e => setBaseUrl(e.target.value)} onChange={e => setBaseUrl(e.target.value)}
/> />
+4 -2
View File
@@ -319,8 +319,10 @@ const Apps = (props) => {
<div> <div>
<h2>{newAppname}</h2> <h2>{newAppname}</h2>
<p>{description}</p> <p>{description}</p>
<p>{selectedApp.id}</p> <Divider style={{marginBottom: "10px", marginTop: "10px", backgroundColor: dividerColor}}/>
<p>{selectedApp.privateId}</p> <p>URL: {selectedApp.link}</p>
<p>ID: {selectedApp.id}</p>
<p>PrivateID: {selectedApp.privateId}</p>
{editButton} {editButton}
{deleteButton} {deleteButton}
</div> </div>
+1 -1
View File
@@ -474,7 +474,7 @@ const Workflows = (props) => {
var t = new Date(data.started_at*1000) var t = new Date(data.started_at*1000)
var showResult = data.result.trim() var showResult = data.result.trim()
if (showResult.startsWith("{") && showResult.endsWith("}")) { if ((showResult.startsWith("{") && showResult.endsWith("}")) || (showResult.startsWith("[{") && showResult.endsWith("}]"))) {
//showResult = <JSONPretty //showResult = <JSONPretty
// id="json-pretty" // id="json-pretty"
// theme={JSONPrettyMon} // theme={JSONPrettyMon}
+2 -1
View File
@@ -344,9 +344,10 @@ class AppBase:
params = {} params = {}
try: try:
for item in action["authentication"]: for item in action["authentication"]:
print(key, value) print("AUTH: ", key, value)
params[item["key"]] = item["value"] params[item["key"]] = item["value"]
except KeyError: except KeyError:
print("No authentication specified!")
pass pass
#action["authentication"] #action["authentication"]