asgard
asgard copied to clipboard
Wiki documentation for user data customization incorrect
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)
} }
Does anyone have input on how the wiki documentation can be updated to address this issue?
+1 Please...spent a good 2 hours trying to implement this until I found this.
+1 the wiki is still incorrect