如何读取Azure存储密钥

时间:2019-04-20 10:37:55

标签: azure azure-storage azure-storage-blobs

我有一个Azure存储连接字符串,我想从中读取 AccountName Account Key
我可以获取帐户名,但不能获取密钥
谁能建议我阅读 Key

  

ConnectionString:DefaultEndpointsProtocol = https; AccountName = dev; AccountKey = tsdsgyduysaugdsay4aR6EPn2Ie9YOILeEp5RRFXeeaJ9; EndpointSuffix = core.windows.net

  @Override
public void onStart() {
    super.onStart();

    Query conversationQuery = mConvDatabase.orderByChild("timestamp");


    FirebaseRecyclerAdapter<Conv, ConvViewHolder> firebaseConvAdapter = new FirebaseRecyclerAdapter<Conv, ConvViewHolder>(
            Conv.class,
            R.layout.users_layout,
            ConvViewHolder.class,
            conversationQuery
    ) {
        @Override
        protected void populateViewHolder(final ConvViewHolder convViewHolder, final Conv conv, int i) {


            final String list_user_id = getRef(i).getKey();

           // Query MessageQuery = mMessageDatabase.child(list_user_id);


            Query lastMessageQuery = mMessageDatabase.child(list_user_id).limitToLast(1);

            lastMessageQuery.addChildEventListener(new ChildEventListener() {
                @Override
                public void onChildAdded(DataSnapshot dataSnapshot, String s) {

                    String data = dataSnapshot.child("message").getValue().toString();
                    String type_image = dataSnapshot.child("type").getValue().toString();

                    boolean seen = Boolean.parseBoolean(dataSnapshot.getKey());


                    if (type_image.equals("image")){
                         convViewHolder.setMessage("image",conv.isSeen());
                    }else {

                        convViewHolder.setMessage(data, conv.isSeen());

                }}

                @Override
                public void onChildChanged(DataSnapshot dataSnapshot, String s) {

                }

                @Override
                public void onChildRemoved(DataSnapshot dataSnapshot) {

                }

                @Override
                public void onChildMoved(DataSnapshot dataSnapshot, String s) {

                }

                @Override
                public void onCancelled(DatabaseError databaseError) {

                }
            });

            mUsersDatabase.child(list_user_id).addValueEventListener(new ValueEventListener() {
                @Override
                public void onDataChange(DataSnapshot dataSnapshot) {

                    final String userName = dataSnapshot.child("name").getValue().toString();
                    String userThumb = dataSnapshot.child("thumb_image").getValue().toString();

                    if(dataSnapshot.hasChild("online")) {

                        String userOnline = dataSnapshot.child("online").getValue().toString();
                        convViewHolder.setUserOnline(userOnline, getActivity());

                    }

                    convViewHolder.setName(userName);
                    convViewHolder.setUserImage(userThumb, getContext());

                    convViewHolder.mView.setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View view) {


                            Intent chatIntent = new Intent(getContext(), ChatActivity.class);
                            chatIntent.putExtra("user_id", list_user_id);
                            chatIntent.putExtra("user_name", userName);
                            startActivity(chatIntent);

                        }
                    }); 

                }

                @Override
                public void onCancelled(DatabaseError databaseError) {

                }
            });

        }
    };

    firebaseConvAdapter.registerAdapterDataObserver(new RecyclerView.AdapterDataObserver() {
        @Override
        public void onItemRangeInserted(int positionStart, int itemCount) {
            super.onItemRangeInserted(positionStart, itemCount);

            int chatMessage = firebaseConvAdapter.getItemCount();
            int lastVisiblePosition = linearLayoutManager.findLastCompletelyVisibleItemPosition();

            if (lastVisiblePosition == -1 ||
                    (positionStart >= (chatMessage)&& lastVisiblePosition==(positionStart))){

                mConvList.scrollToPosition(positionStart);

            }
        }
    });
    mConvList.setAdapter(firebaseConvAdapter);

}

1 个答案:

答案 0 :(得分:1)

因此,如果您具有存储凭据(帐户名和密钥)以及Blob的URI,则有两种方法来创建CloudBlockBlob实例。

        var storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=account-name;AccountKey=account-key;EndpointSuffix=core.windows.net;");
        var blob = new CloudBlockBlob(new Uri("https://account-name.blob.core.windows.net/container-name/blob-name"), storageAccount.Credentials);

OR

        var storageAccount = CloudStorageAccount.Parse("DefaultEndpointsProtocol=https;AccountName=account-name;AccountKey=account-key;EndpointSuffix=core.windows.net;");
        var blobClient = storageAccount.CreateCloudBlobClient();
        var blob = new CloudBlockBlob(new Uri("https://account-name.blob.core.windows.net/container-name/blob-name"), blobClient);