Coder Social home page Coder Social logo

Comments (4)

mgoffin avatar mgoffin commented on May 4, 2024

The .add_connection() method works as you attempted to use it:

instantiated_ti_object.add_connection(object_id_that_exists)

However, if instantiated_ti_object in this example is an object that hadn't previously existed in TX prior to you creating it and calling .save() we don't "reload" it properly. Here's the issue:

new = ThreatIndicator()
new.set(TE.ThreatIndicator.STATUS,"MALICIOUS")
new.set(TE.ThreatIndicator.CONFIDENCE,"100")
new.set(TE.ThreatIndicator.TYPE,"URI")
new.set(TE.ThreatIndicator.INDICATOR, someurl)
# set the rest of the necessary stuff....
new.save() # HERE IS THE ISSUE
new.add_connection("object_id_that_exists_in_tx_already")

When you do .save(), TX will generate an Object ID and assign it to the new Threat Indicator. When we get the response from the server, we just return it to you. This means that your new object in this example doesn't have an id still and thus doesn't have a properly formatted DETAILS or RELATED URL attribute. So when you go to add a connection, it fails because the URL it uses is wrong.

What we should do is consume the server response on .save(), and if it is successful and contains an ID, set the ID on our object which should automatically set the URLs for us.

Thanks for catching this!

from threatexchange.

mgoffin avatar mgoffin commented on May 4, 2024

I have this ready to go if you'd like to test it:

f4f1c0a

I haven't submitted it for a PR because I want the Travis PR to be accepted and going first before submitting any more code changes :)

from threatexchange.

raajks2489 avatar raajks2489 commented on May 4, 2024

You are right. It doesn't reload the object properly. So, I did something like the following after save():
result=new.save()
new2= ThreatIndicator.details(id=result['id'])
new2.add_connection(object_id_already_exists)

Thanks for looking into this. I will test the change sometime.

from threatexchange.

mgoffin avatar mgoffin commented on May 4, 2024

Thanks! if you test my changes please respond so we can get some input from more than just me! If it works out for you I can get a PR up and running eventually :)

from threatexchange.

Related Issues (20)

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.