Code Monkey home page Code Monkey logo

firepyer's People

Contributors

certanet avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

firepyer's Issues

Objects overwrite feature

Hi, would be nice to add a new feature where we can send overwrite=True in case we want to overwrite an object that's already exists.
I have kind of created my own functions for it, cuz I want "idempotency" in my automation, so if someone has already created a network-object group, I want to overwrite it, or later, that network-object changed it's value, i want to overwrite it,
I am not proficient enough in python to create a PR but would love to do it.

def create_network_object(fdm_object: object, name: str, value: str, type: str) -> dict:
    """
    Create a network object in FDM, overwrite if already exists.
    """
    try:
        network_object = fdm_object.create_network(type=type, name=name, value=value)
        return network_object
    except FirepyerError as e:
        if "duplicate name" in str(e):
            existing_network_object = fdm_object.get_net_objects(name)
            pprint(existing_network_object)
            print(f"Network object {name} already exists")
            print("Updating network object")
            existing_network_object["value"] = value
            existing_network_object[
                "subType"
            ] = (
                type.upper()
            )  # Capitalization needed since we're sending directly to api
            pprint(existing_network_object)
            put_it = fdm_object.put_api(
                f"/object/networks/{existing_network_object['id']}",
                json.dumps(existing_network_object),
            )
            if put_it.status_code == 200 or put_it.status_code == 204:
                print("Network object updated")
                return existing_network_object
            else:
                raise FirepyerError(
                    f"Failed to update network object {name} with status code {put_it.status_code}\n{put_it.text}"
                )
        else:
            raise e

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.