Пример #1
0
def createKey(
  user_email="",
  key_name="",
  key_value="",
  env_id: uuid.UUID = uuid.uuid4(),
  enterprise_id: uuid.UUID = uuid.uuid4(),
  project_id: uuid.UUID = uuid.uuid4()
):
  try:

    user = getUser(user_email)
    enterprise = getEnterpriseModel(user=user, enterprise_id=enterprise_id)
    if enterprise["error"]: return enterprise
    enterprise = enterprise["message"]

    project = getProjectModel(user=user, enterprise=enterprise, project_id=project_id)
    if project["error"]: return project
    project = project["message"]

    env = getEnvModel(user=user, enterprise=enterprise, project=project, env_id=env_id)
    if env["error"]: return env
    env = env["message"]

    ciphered_key_value = __cipherData(key_value)
    key = KeyModel(name = key_name, value=ciphered_key_value)
    env.key_list.append(key)

    env.save()

    return {"message": "Key created correctly", "error": False}
  except Exception as error:
    return {"message": f"Some error has happend in createKey function in key_consumer: {error}", "error": True}
Пример #2
0
def getKeys(
  user_email="",
  enterprise_id: uuid.UUID = uuid.uuid4(),
  project_id: uuid.UUID = uuid.uuid4(),
  env_id: uuid.UUID = uuid.uuid4(),
  user: UserModel = None,
  enterprise: EnterpriseModel = None,
  project: ProjectModel = None,
):
  try:
    if not user: user = getUser(user_email)

    if not enterprise:
      enterprise = getEnterpriseModel(user = user, enterprise_id = enterprise_id)
      if enterprise["error"]: return enterprise
      enterprise = enterprise["message"]   

    if not project:
      project = getProjectModel(user=user, enterprise=enterprise, project_id=project_id)
      if project["error"]: return project
      project = project["message"]

    if not env:
      env = getEnvModel(user=user, enterprise=enterprise, project=project, env_id=env_id)
      if env["error"]: return env
      env = env["message"]

    keys = env["message"].key_list

    return {"message": None, "error": False, "data": keys}

  except Exception as error:
    return {"message": f"Some error has happend: {error}", "error": True}
Пример #3
0
def createEnv(
  user_email="",
  env_name="",
  enterprise_id: uuid.UUID = uuid.uuid4(),
  project_id: uuid.UUID = uuid.uuid4()
):
  try:

    user = getUser(user_email)
    enterprise = getEnterpriseModel(user=user, enterprise_id=enterprise_id)
    if enterprise["error"]: return enterprise
    enterprise = enterprise["message"]

    project = getProjectModel(user=user, enterprise=enterprise, project_id=project_id)
    if project["error"]: return project
    project = project["message"]

    env = EnvModel(name = env_name)
    project.envs.append(env.id)

    env.save()
    project.save()

    return {"message": "Env created correctly", "error": False}
  except Exception as error:
    return {"message": f"Some error has happend: {error}", "error": True}
Пример #4
0
def getEnvs(
  user_email="",
  enterprise_id: uuid.UUID = uuid.uuid4(),
  project_id: uuid.UUID = uuid.uuid4(),
  user: UserModel = None,
  enterprise: EnterpriseModel = None,
  project: ProjectModel = None
):
  try:
    if not user: user = getUser(user_email)

    if not enterprise:
      enterprise = getEnterpriseModel(user = user, enterprise_id = enterprise_id)
      if enterprise["error"]: return enterprise
      enterprise = enterprise["message"]   

    if not project:
      project = getProjectModel(user=user, enterprise=enterprise, project_id=project_id)
      if project["error"]: return project
      project = project["message"]

    envs = EnvModel.objects(id__in = project.envs).aggregate({
      "$project":{
        "id": "$id.uuid",
        "name": 1,
        "created_at": 1,
        "image_src": 1
      }
    })

    return {"message": list(envs), "error": False}

  except Exception as error:
    return {"message": f"Some error has happend: {error}", "error": True}
Пример #5
0
def deleteEnv(
  user_email="",
  enterprise_id: uuid.UUID = uuid.uuid4(),
  project_id: uuid.UUID = uuid.uuid4(),
  env_id: uuid.UUID = uuid.uuid4(),
  user: UserModel = None,
  enterprise: EnterpriseModel = None,
  project: ProjectModel = None
):
  try:
    if not user: user = getUser(user_email)
    if not enterprise:
      enterprise = getEnterpriseModel(user=user, enterprise_id=enterprise_id)
      if enterprise["error"]: return enterprise
      enterprise = enterprise["message"]
    if not project:
      project = getProjectModel(user=user, enterprise=enterprise, project_id=project_id)
      if project["error"]: return project
      project = project["message"]

    if not enterprise_id in user.enterprises: return {"message": "Unable to find this enterprise in your profile", "error": True, "data": None}
    if not project_id in enterprise.projects: return {"message": "Unable to find this project in your profile", "error": True, "data": None}
    if not env_id in project.envs: return {"message": "Unable to find this env in your profile", "error": True, "data": None}

    env = EnvModel.objects.filter(id = env_id).delete()
    env.save()
    
    project.envs.remove(env_id)
    project.save()

    return {"message": "Key deleted correctly", "error": False, "data": None}
  except Exception as error:
    print(f"Some error has happend deleting key at key_consumer.py. error: {error}")
    return {"message": f"Some error has happend: {error}", "error": True}
Пример #6
0
def getEnvModel(
  user_email="",
  enterprise_id: uuid.UUID = uuid.uuid4(),
  project_id: uuid.UUID = uuid.uuid4(),
  env_id: uuid.UUID = uuid.uuid4(),
  user: UserModel = None,
  enterprise: EnterpriseModel = None,
  project: ProjectModel = None
):
  try:
    if not user: user = getUser(user_email)
    if not enterprise:
      enterprise = getEnterpriseModel(user=user, enterprise_id=enterprise_id)
      if enterprise["error"]: return enterprise
      enterprise = enterprise["message"]
    if not project:
      project = getProjectModel(user=user, enterprise_id=enterprise_id, project_id=project_id)
      if project["error"]: return project
      project = project["message"]

    if env_id in project.envs:
      env = EnvModel.objects(id = env_id).first()
      return {"message": env, "error": False}
      
  except Exception as error:
    return {"message": f"Some error has happend in getEnvModel at env_consumer: {error}", "error": True}
Пример #7
0
def getKey(
  user_email="",
  enterprise_id: uuid.UUID = uuid.uuid4(),
  project_id: uuid.UUID = uuid.uuid4(),
  env_id: uuid.UUID = uuid.uuid4(),
  key_id: uuid.UUID = uuid.uuid4(),
  user: UserModel = None,
  enterprise: EnterpriseModel = None,
  project: ProjectModel = None,
  env: EnvModel = None
):
  try:
    if not user: user = getUser(user_email)

    if not enterprise:
      enterprise = getEnterpriseModel(user=user, enterprise_id=enterprise_id)
      if enterprise["error"]: return enterprise
      enterprise = enterprise["message"]

    if not project:
      project = getProjectModel(user=user, enterprise=enterprise, project_id=project_id)
      if project["error"]: return project
      project = project["message"]

    if not env:
      env = getEnvModel(user=user, enterprise=enterprise, project=project, env_id=env_id)
      if env["error"]: return env
      env = env["message"]

    key = env.keys_list.object.filter(id = key_id).aggregate({
        "$project":{
          "id": "$id.uuid",
          "name": 1,
          "created_at": 1 
        }
      })
    key = list(key)
    key_len = len(key)
    if key_len:
      return {"message": None, "error": False, "data": key}
  except Exception as error:
    return {"message": f"Some error has happend: {error}", "error": True}