Fixed API authentication for files
This commit is contained in:
@@ -29,7 +29,7 @@ BACKEND_PORT=5001
|
||||
FRONTEND_PORT=3001
|
||||
FRONTEND_PORT_HTTPS=3443
|
||||
OUTER_HOSTNAME=shuffle-backend
|
||||
DB_LOCATION=./shuffle-database
|
||||
DB_LOCATION=./shuffle-database-new
|
||||
|
||||
# Proxy configurations. SHUFFLE_PASS_WORKER_PROXY must be FALSE to not pass the proxy information to sub-apps.
|
||||
# PS: It will skip proxy for
|
||||
|
||||
@@ -701,7 +701,8 @@ func handleCreateFile(resp http.ResponseWriter, request *http.Request) {
|
||||
|
||||
// Loads of validation below
|
||||
if len(curfile.Filename) == 0 || len(curfile.OrgId) == 0 || len(curfile.WorkflowId) == 0 {
|
||||
log.Printf("[ERROR] Missing field during upload.")
|
||||
log.Printf("[ERROR] Missing field during fileupload. Required: filename, org_id, workflow_id")
|
||||
log.Printf("INPUT: %s", string(body))
|
||||
resp.WriteHeader(401)
|
||||
resp.Write([]byte(fmt.Sprintf(`{"success": false, "reason": "Missing field. Required: filename, org_id, workflow_id"}`)))
|
||||
return
|
||||
|
||||
@@ -614,13 +614,13 @@ func handleApiAuthentication(resp http.ResponseWriter, request *http.Request) (U
|
||||
apikey := request.Header.Get("Authorization")
|
||||
if len(apikey) > 0 {
|
||||
if !strings.HasPrefix(apikey, "Bearer ") {
|
||||
log.Printf("Apikey doesn't start with bearer")
|
||||
log.Printf("[WARNING] Apikey doesn't start with bearer")
|
||||
return User{}, errors.New("No bearer token for authorization header")
|
||||
}
|
||||
|
||||
apikeyCheck := strings.Split(apikey, " ")
|
||||
if len(apikeyCheck) != 2 {
|
||||
log.Printf("Invalid format for apikey.")
|
||||
log.Printf("[WARNING] Invalid format for apikey.")
|
||||
return User{}, errors.New("Invalid format for apikey")
|
||||
}
|
||||
|
||||
@@ -643,7 +643,7 @@ func handleApiAuthentication(resp http.ResponseWriter, request *http.Request) (U
|
||||
if len(Userdata.Username) > 0 {
|
||||
return Userdata, nil
|
||||
} else {
|
||||
return Userdata, errors.New(fmt.Sprintf("User is invalid - no username found"))
|
||||
return Userdata, errors.New(fmt.Sprintf("[WARNING] User is invalid - no username found"))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+45
-16
@@ -909,8 +909,8 @@ func validateNewWorkerExecution(body []byte) error {
|
||||
return err
|
||||
}
|
||||
|
||||
log.Printf("LEN: %s", string(body))
|
||||
log.Printf("LEN: %d", len(string(body)))
|
||||
//log.Printf("LEN: %s", string(body))
|
||||
//log.Printf("LEN: %d", len(string(body)))
|
||||
baseExecution, err := getWorkflowExecution(ctx, execution.ExecutionId)
|
||||
if err != nil {
|
||||
log.Printf("[ERROR] Failed getting execution (workflowqueue) %s: %s", execution.ExecutionId, err)
|
||||
@@ -1710,7 +1710,7 @@ func setNewWorkflow(resp http.ResponseWriter, request *http.Request) {
|
||||
user.ActiveOrg.Users = []User{}
|
||||
workflow.ExecutingOrg = user.ActiveOrg
|
||||
workflow.OrgId = user.ActiveOrg.Id
|
||||
log.Printf("TRIGGERS: %d", len(workflow.Triggers))
|
||||
//log.Printf("TRIGGERS: %d", len(workflow.Triggers))
|
||||
|
||||
ctx := context.Background()
|
||||
//err = increaseStatisticsField(ctx, "total_workflows", workflow.ID, 1, workflow.OrgId)
|
||||
@@ -1744,7 +1744,7 @@ func setNewWorkflow(resp http.ResponseWriter, request *http.Request) {
|
||||
|
||||
// Initialized without functions = adding a hello world node.
|
||||
if len(newActions) == 0 {
|
||||
log.Printf("APPENDING NEW APP FOR NEW WORKFLOW")
|
||||
//log.Printf("APPENDING NEW APP FOR NEW WORKFLOW")
|
||||
|
||||
// Adds the Testing app if it's a new workflow
|
||||
workflowapps, err := getAllWorkflowApps(ctx)
|
||||
@@ -2188,8 +2188,10 @@ func saveWorkflow(resp http.ResponseWriter, request *http.Request) {
|
||||
|
||||
workflowapps, apperr := getAllWorkflowApps(ctx)
|
||||
allAuths, err := getAllWorkflowAppAuth(ctx, user.ActiveOrg.Id)
|
||||
if err == nil && len(allAuths) > 0 && len(workflowapps) > 0 && apperr == nil {
|
||||
if err == nil && len(workflowapps) > 0 && apperr == nil {
|
||||
log.Printf("Setting actions")
|
||||
actionFixing := []Action{}
|
||||
appsAdded := []string{}
|
||||
for _, action := range newActions {
|
||||
setAuthentication := false
|
||||
if len(action.AuthenticationId) > 0 {
|
||||
@@ -2253,6 +2255,12 @@ func saveWorkflow(resp http.ResponseWriter, request *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
for _, added := range appsAdded {
|
||||
if outerapp.ID == added {
|
||||
found = true
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: Add app auth
|
||||
if !found {
|
||||
timeNow := int64(time.Now().Unix())
|
||||
@@ -2281,6 +2289,8 @@ func saveWorkflow(resp http.ResponseWriter, request *http.Request) {
|
||||
err = setWorkflowAppAuthDatastore(ctx, appAuth, appAuth.Id)
|
||||
if err != nil {
|
||||
log.Printf("Failed setting appauth for with name %s", appAuth.Label)
|
||||
} else {
|
||||
appsAdded = append(appsAdded, outerapp.ID)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2299,14 +2309,16 @@ func saveWorkflow(resp http.ResponseWriter, request *http.Request) {
|
||||
}
|
||||
|
||||
newActions = actionFixing
|
||||
} else {
|
||||
log.Printf("Err: %s - %s", err, apperr)
|
||||
//workflowapps, apperr := getAllWorkflowApps(ctx)
|
||||
//allAuths, err := getAllWorkflowAppAuth(ctx, user.ActiveOrg.Id)
|
||||
}
|
||||
|
||||
//workflow.PreviouslySaved = true
|
||||
workflow.PreviouslySaved = true
|
||||
}
|
||||
//PreviouslySaved bool `json:"first_save" datastore:"first_save"`
|
||||
|
||||
workflow.Actions = newActions
|
||||
|
||||
newTriggers := []Trigger{}
|
||||
for _, trigger := range workflow.Triggers {
|
||||
log.Printf("Trigger %s: %s", trigger.TriggerType, trigger.Status)
|
||||
@@ -3421,15 +3433,19 @@ func handleExecution(id string, workflow Workflow, request *http.Request) (Workf
|
||||
return WorkflowExecution{}, "Failed building missing Docker images", err
|
||||
}
|
||||
|
||||
b, err := json.Marshal(workflowExecution)
|
||||
if err == nil {
|
||||
log.Printf("%s", string(b))
|
||||
log.Printf("LEN: %d", len(string(b)))
|
||||
//workflowExecution.ExecutionOrg.SyncFeatures = Org{}
|
||||
}
|
||||
//b, err := json.Marshal(workflowExecution)
|
||||
//if err == nil {
|
||||
// log.Printf("%s", string(b))
|
||||
// log.Printf("LEN: %d", len(string(b)))
|
||||
// //workflowExecution.ExecutionOrg.SyncFeatures = Org{}
|
||||
//}
|
||||
|
||||
workflowExecution.Workflow.ExecutingOrg = Org{}
|
||||
workflowExecution.Workflow.Org = []Org{}
|
||||
workflowExecution.Workflow.ExecutingOrg = Org{
|
||||
Id: workflowExecution.Workflow.ExecutingOrg.Id,
|
||||
}
|
||||
workflowExecution.Workflow.Org = []Org{
|
||||
workflowExecution.Workflow.ExecutingOrg,
|
||||
}
|
||||
//Org []Org `json:"org,omitempty" datastore:"org"`
|
||||
err = setWorkflowExecution(ctx, workflowExecution, true)
|
||||
if err != nil {
|
||||
@@ -4735,6 +4751,7 @@ func setAuthenticationConfig(resp http.ResponseWriter, request *http.Request) {
|
||||
}
|
||||
|
||||
if config.Action == "assign_everywhere" {
|
||||
log.Printf("Should set authentication config")
|
||||
q := datastore.NewQuery("workflow").Filter("org_id =", user.ActiveOrg.Id)
|
||||
q = q.Order("-edited").Limit(35)
|
||||
|
||||
@@ -4750,14 +4767,21 @@ func setAuthenticationConfig(resp http.ResponseWriter, request *http.Request) {
|
||||
// FIXME: Add function to remove auth from other auth's
|
||||
actionCnt := 0
|
||||
workflowCnt := 0
|
||||
authenticationUsage := []AuthenticationUsage{}
|
||||
for _, workflow := range workflows {
|
||||
newActions := []Action{}
|
||||
edited := false
|
||||
usage := AuthenticationUsage{
|
||||
WorkflowId: workflow.ID,
|
||||
Nodes: []string{},
|
||||
}
|
||||
|
||||
for _, action := range workflow.Actions {
|
||||
if action.AppName == auth.App.Name {
|
||||
//log.Printf("FOUND ACTION TO UPDATE: %#v", action)
|
||||
edited = true
|
||||
actionCnt += 1
|
||||
usage.Nodes = append(usage.Nodes, action.ID)
|
||||
}
|
||||
|
||||
newActions = append(newActions, action)
|
||||
@@ -4765,6 +4789,8 @@ func setAuthenticationConfig(resp http.ResponseWriter, request *http.Request) {
|
||||
|
||||
workflow.Actions = newActions
|
||||
if edited {
|
||||
//auth.Usage = usage
|
||||
authenticationUsage = append(authenticationUsage, usage)
|
||||
err = setWorkflow(ctx, workflow, workflow.ID)
|
||||
if err != nil {
|
||||
log.Printf("Failed setting (authupdate) workflow: %s", err)
|
||||
@@ -4775,9 +4801,12 @@ func setAuthenticationConfig(resp http.ResponseWriter, request *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
//Usage []AuthenticationUsage `json:"usage" datastore:"usage"`
|
||||
log.Printf("Found %d workflows, %d actions", workflowCnt, actionCnt)
|
||||
if actionCnt > 0 && workflowCnt > 0 {
|
||||
auth.WorkflowCount = int64(workflowCnt)
|
||||
auth.NodeCount = int64(actionCnt)
|
||||
auth.Usage = authenticationUsage
|
||||
|
||||
err = setWorkflowAppAuthDatastore(ctx, *auth, auth.Id)
|
||||
if err != nil {
|
||||
|
||||
+3
-3
@@ -1,7 +1,7 @@
|
||||
version: '3'
|
||||
services:
|
||||
frontend:
|
||||
build: ./frontend
|
||||
#build: ./frontend
|
||||
image: ghcr.io/frikky/shuffle-frontend:0.8.53
|
||||
container_name: shuffle-frontend
|
||||
hostname: shuffle-frontend
|
||||
@@ -16,8 +16,8 @@ services:
|
||||
depends_on:
|
||||
- backend
|
||||
backend:
|
||||
#build: ./backend
|
||||
image: ghcr.io/frikky/shuffle-backend:0.8.53
|
||||
build: ./backend
|
||||
image: ghcr.io/frikky/shuffle-backend:0.8.54
|
||||
container_name: shuffle-backend
|
||||
hostname: ${BACKEND_HOSTNAME}
|
||||
# Here for debugging:
|
||||
|
||||
+4
-3
@@ -8,7 +8,8 @@ ENV PATH /usr/src/app/node_modules/.bin:$PATH
|
||||
|
||||
COPY package.json /usr/src/app/package.json
|
||||
|
||||
RUN npm install --verbose
|
||||
#RUN npm install --verbose
|
||||
RUN yarn install
|
||||
|
||||
# copy only required files to not trigger rebuilding every time
|
||||
COPY ./certs /usr/src/app/certs/
|
||||
@@ -19,9 +20,9 @@ COPY ./*.json /usr/src/app/
|
||||
|
||||
# There were issues with the webpack installer from package.json
|
||||
RUN rm -rf /usr/src/app/node_modules/webpack
|
||||
RUN npm install webpack@4.42.0
|
||||
#RUN yarn add webpack@4.42.0
|
||||
|
||||
RUN npm run-script build
|
||||
RUN yarn build
|
||||
|
||||
# Production environment
|
||||
FROM nginx:latest
|
||||
|
||||
@@ -301,6 +301,7 @@ const Admin = (props) => {
|
||||
} else {
|
||||
//alert.success("Successfully password!")
|
||||
setSelectedUserModalOpen(false)
|
||||
getAppAuthentication()
|
||||
}
|
||||
}),
|
||||
)
|
||||
@@ -762,6 +763,7 @@ const Admin = (props) => {
|
||||
.then((responseJson) => {
|
||||
if (responseJson.success) {
|
||||
//console.log(responseJson.data)
|
||||
console.log(responseJson)
|
||||
setAuthentication(responseJson.data)
|
||||
} else {
|
||||
alert.error("Failed getting authentications")
|
||||
@@ -2033,7 +2035,7 @@ const Admin = (props) => {
|
||||
<div style={{marginTop: 20, marginBottom: 20,}}>
|
||||
<h2 style={{display: "inline",}}>App Authentication</h2>
|
||||
<span style={{marginLeft: 25}}>Control the authentication options for individual apps. <b>Actions can be destructive!</b></span>
|
||||
. <a target="_blank" href="https://shuffler.io/docs/organizations#app_authentication" style={{textDecoration: "none", color: "#f85a3e"}}>Learn more</a>
|
||||
<a target="_blank" href="https://shuffler.io/docs/organizations#app_authentication" style={{textDecoration: "none", color: "#f85a3e"}}>Learn more</a>
|
||||
</div>
|
||||
<Divider style={{marginTop: 20, marginBottom: 20, backgroundColor: theme.palette.inputColor}}/>
|
||||
<List>
|
||||
@@ -2087,7 +2089,7 @@ const Admin = (props) => {
|
||||
style={{minWidth: 150, maxWidth: 150}}
|
||||
/>
|
||||
<ListItemText
|
||||
primary={data.usage === null ? 0 : data.usage.length}
|
||||
primary={data.workflow_count === null ? 0 : data.workflow_count}
|
||||
style={{minWidth: 110, maxWidth: 110, overflow: "hidden"}}
|
||||
/>
|
||||
<ListItemText
|
||||
@@ -2108,14 +2110,29 @@ const Admin = (props) => {
|
||||
>
|
||||
<EditIcon color="primary"/>
|
||||
</IconButton>
|
||||
<IconButton
|
||||
style={{marginRight: 10}}
|
||||
onClick={() => {
|
||||
editAuthenticationConfig(data.id)
|
||||
}}
|
||||
>
|
||||
<SelectAllIcon color="primary"/>
|
||||
</IconButton>
|
||||
{data.defined ?
|
||||
<Tooltip color="primary" title="Set in EVERY workflow" placement="top">
|
||||
<IconButton
|
||||
style={{marginRight: 10}}
|
||||
disabled={data.defined === false}
|
||||
onClick={() => {
|
||||
editAuthenticationConfig(data.id)
|
||||
}}
|
||||
>
|
||||
<SelectAllIcon color={data.defined ? "primary" : "secondary"} />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
:
|
||||
<Tooltip color="primary" title="Must edit before you can set in all workflows" placement="top">
|
||||
<IconButton
|
||||
style={{marginRight: 10}}
|
||||
onClick={() => {
|
||||
}}
|
||||
>
|
||||
<SelectAllIcon color={data.defined ? "primary" : "secondary"} />
|
||||
</IconButton>
|
||||
</Tooltip>
|
||||
}
|
||||
<IconButton
|
||||
onClick={() => {
|
||||
deleteAuthentication(data)
|
||||
|
||||
@@ -948,7 +948,16 @@ const AngularWorkflow = (props) => {
|
||||
})
|
||||
.then((responseJson) => {
|
||||
if (responseJson.success) {
|
||||
setAppAuthentication(responseJson.data)
|
||||
var newauth = []
|
||||
for (var key in responseJson.data) {
|
||||
if (responseJson.data[key].defined === false) {
|
||||
continue
|
||||
}
|
||||
|
||||
newauth.push(responseJson.data[key])
|
||||
}
|
||||
|
||||
setAppAuthentication(newauth)
|
||||
} else {
|
||||
alert.error("Failed getting authentications")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user