func (s *S) TestCredentialsFileAuth(c *check.C) {
	file, err := ioutil.TempFile("", "creds")

	if err != nil {
		c.Fatal(err)
	}

	iniFile := `

[default] ; comment 123
aws_access_key_id = keyid1 ;comment
aws_secret_access_key=key1     

	[profile2]
    aws_access_key_id = keyid2 ;comment
	aws_secret_access_key=key2     
	aws_session_token=token1

`
	_, err = file.WriteString(iniFile)
	if err != nil {
		c.Fatal(err)
	}

	err = file.Close()
	if err != nil {
		c.Fatal(err)
	}

	// check non-existant profile
	_, err = aws.CredentialFileAuth(file.Name(), "no profile", 30*time.Minute)
	c.Assert(err, check.Not(check.Equals), nil)

	defaultProfile, err := aws.CredentialFileAuth(file.Name(), "default", 30*time.Minute)
	c.Assert(err, check.Equals, nil)
	c.Assert(defaultProfile.AccessKey, check.Equals, "keyid1")
	c.Assert(defaultProfile.SecretKey, check.Equals, "key1")
	c.Assert(defaultProfile.Token(), check.Equals, "")

	profile2, err := aws.CredentialFileAuth(file.Name(), "profile2", 30*time.Minute)
	c.Assert(err, check.Equals, nil)
	c.Assert(profile2.AccessKey, check.Equals, "keyid2")
	c.Assert(profile2.SecretKey, check.Equals, "key2")
	c.Assert(profile2.Token(), check.Equals, "token1")
}
Beispiel #2
0
func main() {
	hashKey := "java"
	rangeKey := "de1ece0a-28e9-429c-a9a5-b2fc5e2fc3f9"
	usr, err := user.Current()
	homeDir := "."
	if err != nil {
		log.Println("Error gettingcurrent user ", err)
	} else {
		homeDir = usr.HomeDir
		log.Println(" User ", usr, " Home Dir := ", homeDir)
	}
	authCreds, err = aws.CredentialFileAuth(homeDir+"/.aws/credentials", "default", defaultExpiration)
	awsRegion = aws.Regions[defaultAwsRegionName]
	if err != nil {
		log.Println(" Error getting Authentication Creds : ", err)
	}

	dynamoDBServer = dynamodb.Server{}
	dynamoDBServer.Auth = authCreds
	dynamoDBServer.Region = awsRegion
	dynamoDBTable = dynamodb.Table{}
	dynamoDBTable.Name = dynamoDBTableName
	dynamoDBTable.Server = &dynamoDBServer
	primaryKey := dynamodb.PrimaryKey{}
	primaryKey.KeyAttribute = dynamodb.NewStringAttribute("languageId", "S")
	primaryKey.RangeAttribute = dynamodb.NewStringAttribute("cuid", "S")
	attributes := make([]dynamodb.Attribute, 4)
	attributes[0] = *dynamodb.NewStringAttribute("languageId", "S")
	attributes[1] = *dynamodb.NewStringAttribute("cuid", "SK")
	attributes[2] = *dynamodb.NewStringAttribute("myKey", "1234")
	attributes[3] = *dynamodb.NewStringAttribute("another_Attr", "Sample")
	created, err := dynamoDBTable.PutItem(hashKey, rangeKey, attributes)
	if err != nil {
		log.Fatal("Error creating the Dynamo DB Table : ", err.Error())
	} else {
		log.Println("Create Item Status : ", created)
	}
	dynamoDBTable.Key = primaryKey
	key := dynamodb.Key{}
	key.HashKey = hashKey
	key.RangeKey = rangeKey
	item, err := dynamoDBTable.GetItem(&key)
	if err != nil || item == nil {
		log.Println("Error getting Item (Key = ", key, ") : ", err)
	} else {
		log.Println(" Got the Item ", item)
	}
	log.Println("Deleting the same item now !")
	deleted, err := dynamoDBTable.DeleteItem(&key)
	if err != nil {
		log.Fatal("Error deleting the item : ", err.Error())
	} else {
		log.Println("Item Delete Status := ", deleted)
	}
}
Beispiel #3
0
func main() {
	defaultExpiration = 10000
	usr, err := user.Current()
	homeDir := "."
	if err != nil {
		log.Println("Error gettingcurrent user ", err)
	} else {
		homeDir = usr.HomeDir
		log.Println(" User ", usr, " Home Dir := ", homeDir)
	}
	authCreds, err = aws.CredentialFileAuth(homeDir+"/.aws/credentials", "default", defaultExpiration)
	awsRegion = aws.Regions[defaultAwsRegionName]
	if err != nil {
		log.Println(" Error getting Authentication Creds : ", err)
	}

	sqsService = sqs.New(authCreds, awsRegion)
	sqsQueue, err = sqsService.GetQueue(sqsQueueName)
	if err != nil {
		log.Println("Error getting SQS Queue (", sqsQueueName, ") : ", err)
	}
	log.Println("Sending Message...")
	messageBody := "Hello World!"
	sendResponse, err := sqsQueue.SendMessage(messageBody)
	if err != nil {
		log.Fatal("Message Sending Error : ", err)
	} else {
		log.Println("Message Send Response = ", sendResponse)
	}
	log.Println("Receiving Message...")
	receiveResponse, err := sqsQueue.ReceiveMessage(1)
	if err != nil {
		log.Println("Error receiving next message : ", err)
		return
	}
	log.Println(" Receive Response : ", receiveResponse)
	if len(receiveResponse.Messages) > 0 {
		for _, msg := range receiveResponse.Messages {
			msgAttrbs := msg.MessageAttribute
			log.Println(" Message := ", msg, " Attributes = ", msgAttrbs)
		}
	} else {
		log.Println("No Messages found in the Queue")
	}
	log.Println("Deleting the received Message after processing !")
	if len(receiveResponse.Messages) > 0 {
		for _, msg := range receiveResponse.Messages {
			deleteResponse, err := sqsQueue.DeleteMessage(&msg)
			log.Println(" Delete Response := ", deleteResponse, " Error = ", err)
		}
	}
}