asgard icon indicating copy to clipboard operation
asgard copied to clipboard

Wiki documentation for user data customization incorrect

Open mathianasjs opened this issue 9 years ago • 3 comments

The wiki at https://github.com/Netflix/asgard/wiki/Customizing-User-Data

contains a non working example on how to extend the user data to provide custom environment variables.

This line creates a new instance of DefaultUserDataProvider which is outside the scope of Spring autowire control, so when the defaultProvider.buildUserDataForVariables method is invoked it causes a method inside with an autowired object method to be called result in a null pointer exception. DefaultUserDataProvider defaultProvider = new DefaultUserDataProvider()

The proposed change to the example would be, this would then provide access to the defaultProvider with all autowired dependencies calls made inside the provider.

import com.netflix.asgard.userdata.DefaultUserDataProvider import com.netflix.asgard.UserContext import com.netflix.asgard.plugin.AdvancedUserDataProvider import com.netflix.asgard.model.LaunchContext import javax.xml.bind.DatatypeConverter import com.amazonaws.services.ec2.model.Image import org.springframework.beans.factory.annotation.Autowired

/**

  • Builds user data Initech style. */ class InitechAdvancedUserDataProvider implements AdvancedUserDataProvider { @Autowired DefaultUserDataProvider defaultProvider

    String buildUserData(LaunchContext launchContext) { // Start with Asgard's default user data UserContext userContext = launchContext.userContext String appName = launchContext.application?.name ?: '' String asgName = launchContext.autoScalingGroup?.autoScalingGroupName ?: '' String lcName = launchContext.launchConfiguration?.launchConfigurationName ?: '' String encoded = defaultProvider.buildUserDataForVariables(userContext, appName, asgName, lcName) String defaultUserData = new String(DatatypeConverter.parseBase64Binary(encoded))

    // Add company specific stuff
    String initechMantra = "export IS_THIS_BEST_FOR_THE_COMPANY=true\n"
    Image image = launchContext.image
    String imgDesc = "export IMAGE_DESC=${image.description ?: ''}\n"
    String concatenated = defaultUserData + initechMantra + imgDesc
    DatatypeConverter.printBase64Binary(concatenated.bytes)
    

    } }

mathianasjs avatar Apr 01 '15 14:04 mathianasjs

Does anyone have input on how the wiki documentation can be updated to address this issue?

mathianasjs avatar Apr 16 '15 17:04 mathianasjs

+1 Please...spent a good 2 hours trying to implement this until I found this.

jvasallo avatar Sep 14 '15 21:09 jvasallo

+1 the wiki is still incorrect

Jared-Prime avatar Mar 11 '16 22:03 Jared-Prime