Options
All
  • Public
  • Public/Protected
  • All
Menu

Class AwsOrgNode

A class implementing an AwsOrgNode Interface

remarks

This Class does not expect to be instantiated through its constructor as it needs to be initialised through async AWS API calls Therefore, it must be created through the static function init which will return a new AwsOrgNode: AwsOrgNode.init

Hierarchy

Indexable

[index: string]: any

String indexable, which permits the inclusion of any additional data the AWS API might give us when we merge results in

Index

Constructors

constructor

  • new AwsOrgNode(Id?: string, nodetype?: string): AwsOrgNode
  • Creates a new instance of AwsOrgNode

    remarks

    The constructor is basically empty because we need to call async functions when we initialise the object and therefore we declare the static async function init() which is used in place of the constructor

    see

    AwsOrgNode

    see

    AwsOrgNode.Id

    see

    AwsOrgNode.nodetype

    Parameters

    • Id: string = 'Root'

      The Id property for this AwsOrgNode. Optional. Defaults to special string 'Root'A

    • nodetype: string = 'ROOT'

      The nodetype property for this AwsOrgNode. Optional. Defaults to 'ROOT'

    Returns AwsOrgNode

    A placeholder AwsOrgNode object

Properties

Optional Arn

Arn: string

Amazon Resource Name (ARN) of this node

Children

Children: AwsOrgNode[]

Array of Child AwsOrgNode Objects that are direct descendants

defaultvalue

[]

Id

Id: string

ID of the Node: [ 'Root', 'r-0abc', 'ou-0abc-abcdefgh', '123456789012' ]

remarks

This is the ID of an AWS Organizations object, but as an Organization may only have one root, it is not critical to initialise a ROOT AwsOrgNode with its Id; it's not worth doing a listRoots call just to find it at construction-time; therefore we permit the special value 'Root' which is also the default

defaultvalue

Root

Optional Name

Name: string

Name of this node

Organization

Organization: undefined | Organization

The result of Organizations.describeOrganization, when this is a ROOT node

Optional Type

Type: string

Type of this node

remarks

This property is not normally used in our objects, but can be merged in from an Organizations.listChildren response, and therefore need to be an optional property

nodetype

nodetype: string

Type of AWS Organizations node: [ 'ROOT', 'ORGANIZATIONAL_UNIT', 'ACCOUNT' ]

defaultvalue

ROOT

Methods

addChild

getAccount

  • getAccount(Id: string, recursive?: boolean): undefined | AwsOrgNode
  • Get an ACCOUNT AwsOrgNode Object that is a child of this AwsOrgNode, or optionally of any descendants as well

    Parameters

    • Id: string

      The ID of an ACCOUNT AwsOrgNode to search for in the tree below this node

    • Optional recursive: boolean

      If true, search the whole tree. If false, only search immediate child accounts of this node

    Returns undefined | AwsOrgNode

    An AwsOrgNode object if one is found, or undefined if not

getAccounts

  • getAccounts(recursive?: boolean): AwsOrgNode[]
  • Get an Array of all ACCOUNT AwsOrgNode Objects that are children of this AwsOrgNode, or optionally of any descendants as well

    Parameters

    • Optional recursive: boolean

      If true, get all accounts in the tree below this nose, if false only get immediate child accounts of this node

    Returns AwsOrgNode[]

    An Array of ACCOUNT AwsOrgNode objects

getChild

  • getChild(Id: string): undefined | AwsOrgNode
  • Get an AwsOrgNode Object that is a direct child of this AwsOrgNode by it's Id property

    Parameters

    • Id: string

      The Id of the Child node to find

    Returns undefined | AwsOrgNode

    The AwsOrgNode Object with the provided Id, or undefined if it doesn't exist

getParentOusFor

  • getParentOusFor(Id: string): AwsOrgNode[]
  • Get an Array of AwsOrgNode Objects that are ancestors of the AwsOrgNode, identified by it's Id property, within the tree below this AwsOrgNode - except any that are ROOT nodes.

    remarks

    Identical to getParentsFor, but omit the ROOT, returning only ORGANIZATIONAL_UNITs.

    Parameters

    • Id: string

      The Id of the AwsOrgNode to get the Parents OUs for

    Returns AwsOrgNode[]

    An Array of ORGANIZATIONAL_UNIT AwsOrgNode objects that are antecedent to the object with the Id provided

getParentsFor

  • getParentsFor(Id: string): AwsOrgNode[]
  • Get an Array of AwsOrgNode Objects that are ancestors of the AwsOrgNode within the tree below this AwsOrgNode

    privateremarks

    This could probably be made safer by returning an optional undefined, but for the moment it presumes you wouldn't search for an Object ID that doesn't exist

    Parameters

    • Id: string

      The Id of the AwsOrgNode to get the Parents for

    Returns AwsOrgNode[]

    An Array of AwsOrgNode objects that are antecedent to the object with the Id provided

isAccount

  • isAccount(): boolean
  • Determine if this AwsOrgNode Object is an ACCOUNT

    Returns boolean

    True if the nodetype property is ACCOUNT

isOrganizationalUnit

  • isOrganizationalUnit(): boolean
  • Determine if this AwsOrgNode Object is an ORGANIZATIONAL_UNIT

    Returns boolean

    True if the nodetype property is ORGANIZATIONAL_UNIT

isRoot

  • isRoot(): boolean
  • Determine if this AwsOrgNode Object is a ROOT

    Returns boolean

    True if the nodetype property is ROOT

toString

  • toString(): string
  • Override of toString inherited from Object: "name (id)"

    override

    Returns string

    "this.name (this.id)"

toTree

  • toTree(level?: number): string
  • A string representation of the tree of AwsOrgNodes beneath this one

    Parameters

    • Optional level: number

      A private recursion-control parameter

    Returns string

    A string representation of the AwsOrgNode tree

Static init

  • init(orgNode?: AwsOrgNode, skipSuspended?: boolean, orgAccounts?: AwsOrgNode[], orgParamOverrides?: Record<string, unknown>): Promise<AwsOrgNode>
  • Creates an initialised instance of an AwsOrgNode

    remarks

    This is the real constructor, that calls async functions to populate the Object with the data that makes this object useful By default we are an inferred Organization Root (as opposed to an explicit one defined by an ID like /r-[0-9a-z]{4}/)

    Properties in this class are capitalised based on whether they match data returned from the AWS APIs, or close-enough. nodetype is a concept custom to this class, and therefore lowercase. Arn and Name are returned from the AWS APIs and are therefore TitleCase. This allows us to use Object.assign to merge API results as if they were native object properties.

    example
    const { AwsOrgNode } = require('orgtomate');
    const awsOrg = await AwsOrgNode.init();
    console.log(awsOrg.toTree());
    
    example
    e=async()=>{const {AwsOrgNode}=require('.');console.log((await AwsOrgNode.init(new (require('aws-sdk').Organizations)({region:'us-east-1',maxRetries:100}))).toTree());};e();
    

    Parameters

    • orgNode: AwsOrgNode = ...

      An AwsOrgNode object to initialise. Optional. Defaults to an empty Root node

    • skipSuspended: boolean = false

      Whether to include AWS Accounts in a SUSPENDED state. Optional. Defaults to false

    • orgAccounts: AwsOrgNode[] = []

      The output from org.listAccounts(). Optional. Performed once per tree initialisation, all children are passed the list generated in the parent's initialisation.

    • orgParamOverrides: Record<string, unknown> = {}

    Returns Promise<AwsOrgNode>

    A Promise to return the fully initialised AwsOrgNode Object, with all populated Children

Generated using TypeDoc